I have a User
table defined like this:
CREATE TABLE Users(
UserId int IDENTITY(1,1) NOT NULL,
UserName varchar(128) NOT NULL,
Name nvarchar(200) NOT NULL,
Password binary(64) NOT NULL,
PasswordSalt binary(16) NOT NULL
)
I'm trying to have two class that map to this table:
- The first object, called
User
has no Password and PasswordSalt properties. - The second object, called
SecurityUser
, inherits fromUser
and defines the Password and PasswordSalt properties.
The idea behind this is that SecurityUser
is a internal object that require a intermediate service to modify the password. This is needed to avoid returning the password and salt everytime I need to query a user.
The User
class is, what I call, a safe object that doesn't provide any user sensitive information.
Right now, I have defined two map:
public class UserMap : ClassMap<User>
{
protected UserMap()
{
Id(x => x.Id);
Map(x => x.UserName);
Map(x => x.Name);
}
}
and
public class SecurityUserMap : SubclassMap<SecurityUser>
{
protected SecurityUserMap()
{
Map(x => x.Password);
Map(x => x.PasswordSalt);
Table("Users");
}
}
The problem is that nHibernate creates a table called SecurityUser
. I tried using the Table("Users")
function to specify the same table, but I then get a invalid nhibernate mapping.
How can I achieve what I am trying to do? Or is there is an alternate approach?