I have a user object like so:
public class User
{
public Guid UserId { get; set; }
public string UserName { get; set; }
...
}
this is fluently mapped in nhibernate:
public class UserMap : ClassMap<User>
{
public UserMap()
{
Id(x => x.UserId).Column("UserId");
Map(x => x.UserName).Not.Nullable();
...
}
}
I’m trying to build a credential block that is separate from the user object, so the password and salt are not carried around in the user class like so:
public class UserCredential
{
public User User { get; set; }
public byte[] Password { get; set; }
public string Salt { get; set; }
}
…but I cannot figure out how to properly map this. Ultimately, in the database, I would expect to see a UserId column in the UserCredentials table, that is both a primary key and a foreign key to the Users table. The Users table should have no reference to the UserCredentials table. How would I write that ClassMap<UserCredential> class?
This seems to be a
one-to-onerelationship and would therefore be mapped usingHasOnein FNH.Example
You may be able to map it like this as well: