I’ll need to preface this with the fact that I am a complete newbie when it comes to nhibernate, and I don’t know what I don’t know.
I have a user class like so:
public class nhMembershipUser : MembershipUser
{
public new virtual Guid ProviderUserKey { get; set; }
public new virtual DateTime LastPasswordChangedDate { get; set; }
public virtual bool IsEnabled { get; set; }
protected internal virtual byte[] Password { get; set; }
protected internal virtual string Salt { 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 override 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; }
}
… and a fluent mapping class like so:
public class nhMembershipUserMap : ClassMap<nhMembershipUser>
{
public nhMembershipUserMap()
{
Table("Users");
Id(x => x.ProviderUserKey).Column("UserID");
Map(x => x.Comment).Nullable().Length(10000);
Map(x => x.CreationDate).CustomType<UtcDateTimeType>().Not.Nullable();
Map(x => x.Email).Not.Nullable().Length(250);
Map(x => x.IsApproved).Default("1");
Map(x => x.IsLockedOut).Default("0");
Map(x => x.LastActivityDate).Nullable();
Map(x => x.LastLockoutDate).Nullable();
Map(x => x.LastLoginDate).Nullable();
Map(x => x.LastPasswordChangedDate).Nullable();
Map(x => x.PasswordQuestion).Nullable().Length(250);
Map(x => x.ProviderName).Default("").Not.Nullable().Length(250);
Map(x => x.UserName).Not.Nullable().Length(250);
Map(x => x.IsEnabled).Default("1").Not.Nullable();
Map(Reveal.Member<nhMembershipUser>("Password")).Length(260).Nullable();
Map(Reveal.Member<nhMembershipUser>("Salt")).Length(250).Nullable();
Map(x => x.FirstName).Length(35).Not.Nullable();
Map(x => x.LastName).Length(35).Not.Nullable();
Map(x => x.Application).Length(250).Not.Nullable();
HasManyToMany(x => x.Roles).ChildKeyColumn("RoleId").ParentKeyColumn("UserId").Cascade.All().Table("UsersToRoles");
}
}
This builds, but of course I can’t get or set the Salt or Password properties outside the class, which is bogus. I’m trying to keep my user class light and POCO-ish and build the salting and hashing functionality into my membership provider; I really don’t want the public having access but I want my provider class to. The obvious answer is to use an internal access modifier but NH barks at me when I do that without a protected modifier and that defeats the purpose.
How can I have another class in my assembly access these restricted properties and save to NHibernate? It seems like this should be easily doable.
1 Answer