2011-11-21 2 views
1

nhibernate를 사용하여 자체 멤버십 공급자를 구축하고 있습니다. MembershipUser 클래스는 기본 속성 및 메서드가 모두 가상이 아니기 때문에 주로 nhibernate 매핑에 구h주게하는 것이 놀랍도록 어려운 것입니다. 내 사용자 클래스는 다음과 같이 정의된다 :Fluent NHibernate가 가상 속성없이 클래스를 매핑합니다.

public class nhMembershipUser : MembershipUser 
{ 
    public new virtual Guid ProviderUserKey { get; set; } 
    public new virtual DateTime LastPasswordChangedDate { get; set; } 
    public virtual bool IsEnabled { get; set; } 
    public virtual string FirstName { get; set; } 
    public virtual string LastName { get; set; } 
    public virtual string Application { get; set; } 
    public new virtual string UserName { get; set; } 
    public new virtual bool IsOnline 
    { 
     get 
     { 
      var UnitOfWork = new nhUnitOfWork(); 
      return UnitOfWork.UserIsOnline(this); 
     } 
    } 
    public new virtual bool IsLockedOut { get; set; } 
    public virtual IList<nhRole> Roles { get; set; } 
    public new virtual bool ChangePassword(string oldPassword, string newPassword) 
    { 
     throw new NotSupportedException(); 
    } 
    public new virtual bool ChangePasswordQuestionAndAnswer(string password, string newPasswordQuestion, string newPasswordAnswer) 
    { 
     throw new NotSupportedException(); 
    } 
    public new virtual string ResetPassword() 
    { 
     throw new NotSupportedException(); 
    } 
    public new virtual string ResetPassword(string passwordAnswer) 
    { 
     throw new NotSupportedException(); 
    } 
    public new virtual string GetPassword() 
    { 
     throw new NotSupportedException(); 
    } 
    public new virtual string GetPassword(string passwordAnswer) 
    { 
     throw new NotSupportedException(); 
    } 
} 

내가 내 매핑을 만들려고 해요 때, 나는이납니다 :

FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete conf 
iguration was used while creating a SessionFactory. Check PotentialReasons colle 
ction, and InnerException for more detail. 

    * Database was not configured through Database method. 
---> NHibernate.InvalidProxyTypeException: The following types may not be used 
as proxies: 
nhApplicationServicesProvider.Entities.nhMembershipUser: method Update should be 
'public/protected virtual' or 'protected internal virtual' 
nhApplicationServicesProvider.Entities.nhMembershipUser: method GetPassword shou 
ld be 'public/protected virtual' or 'protected internal virtual' 
nhApplicationServicesProvider.Entities.nhMembershipUser: method ChangePassword s 
hould be 'public/protected virtual' or 'protected internal virtual' 
nhApplicationServicesProvider.Entities.nhMembershipUser: method ResetPassword sh 
ould be 'public/protected virtual' or 'protected internal virtual' 
nhApplicationServicesProvider.Entities.nhRole: method set_RoleId should be 'publ 
ic/protected virtual' or 'protected internal virtual' 
nhApplicationServicesProvider.Entities.nhRole: method set_Name should be 'public 
/protected virtual' or 'protected internal virtual' 
    at NHibernate.Cfg.Configuration.ValidateEntities() 
    at NHibernate.Cfg.Configuration.Validate() 
    at NHibernate.Cfg.Configuration.BuildSessionFactory() 
    at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Build 
s\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 227 
    --- End of inner exception stack trace --- 
    at FluentNHibernate.Cfg.FluentConfiguration.BuildSessionFactory() in d:\Build 
s\FluentNH-v1.x-nh3\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 232 
    at nhApplicationServicesProvider.nhSessionFactory.CreateDatabaseSchema() in C 
:\Users\JHolovacs\Documents\Projects\nhApplicationServicesProvider\nhApplication 
ServicesProvider\nhSessionFactory.cs:line 63 
    at nhApplicationServicesProvider.Program.Main() in C:\Users\JHolovacs\Documen 
ts\Projects\nhApplicationServicesProvider\nhApplicationServicesProvider\Program. 
cs:line 13 

    * Database was not configured through Database method. 

그것은 특별히 GETPASSWORD()과 changepassword() 및 ResetPassword 언급을(), 내가 할 수있는 한, 가상 메소드로 기본 클래스를 적절하게 덮어 쓴다.

왜 이러한 오류가 발생하며 어떻게이 문제를 해결할 수 있습니까?

답변

2

그것은 특히,과 changepassword() 및 ResetPassword()있는, 지금까지의 내가 제대로 가상 방법과 기본 클래스를 덮어 말할 수 GETPASSWORD() 언급하고있다.

아니요,이 방법을 덮어 쓰지 않았습니까?

NHibernate는 비공개 프로퍼티와 메소드가 모두 가상 적이라고 요구한다. 그렇지 않으면 프록시에서 호출을 가로채는 기회가 없다.

클래스를 지연로드하지 않으려면 엔티티를 lazy="false"과 매핑하면 더 이상 가상 멤버가 필요하지 않습니다. 지연로드가 필요한 경우 proxy="ProxyInterface"의 프록시 인터페이스를 사용할 수 있습니다.

+0

와우 나는 공식적으로 이것으로 내 안락 지대에서 벗어나지 만 올바른 대답 인 것 같습니다. 나는 이것을 밖으로 시도하고 답장 할 것이다. –

0

나는 뒤에서 비슷한 필요성이 있었고 this article on CodeProject을 템플릿으로 사용했습니다. 그것은 꽤 잘 작동하는 것처럼 보였다.

이 키는 도메인 개체의 MembershipUser에서 상속하지 말고 도메인 사용자와 회원 사용자간에 변환하는 방법을 제공하는 것입니다 (나는이 기능을 전혀 변경하지 않았다) :

public MembershipUser GetMembershipUserFromUser (User usr) { 
     MembershipUser u = new MembershipUser (this.Name, usr.Username, usr.Id, usr.Email, usr.PasswordQuestion, usr.Comment, usr.IsApproved, usr.IsLockedOut, usr.CreationDate, usr.LastLoginDate, 
     usr.LastActivityDate, usr.LastPasswordChangedDate, usr.LastLockedOutDate); 

     return u; 
    } 
+1

blech ... 깨끗한 코딩의 몇 가지 원칙을 위반하는 것 같습니다. 왜 이런 오류가 나옵니까? 그 문제를 해결해야만한다면, 그렇 겠지만 문제를 이해하고 싶습니다. –

+0

잘 모르겠습니다 만 MS의 회원 가입 아이디어가 내 조직에 유출되는 것을 허용하지 않기로 결정했습니다. MembershipUser로부터 상속 받기를 원한다면 Cremor의 대답이 올바른 방향으로 향할 것이라고 생각합니다. – AlexCuse

관련 문제