You can use the many-to-one association. This FNH mapping is simple:
public class UserMap : ClassMap<User>
{
public UserMap()
{
Id(x => x.Id);
Map(x => x.Name);
References(x => x.Preferences)
.Cascade.All();
}
}
Now the Preferences property can be null, but a single instance of a user's Preferences can be assigned to many instances of User. This can be handled on the domain model side (for example, see Aggregate Roots in DDD).
, - ( ):
public class UserMap : ClassMap<User>
{
public UserMap()
{
Id(x => x.Id);
Map(x => x.Name);
HasOne(x => x.Preferences)
.Cascade.All();
}
}
public class UserPreferencesMap : ClassMap<UserPreferences>
{
public UserPreferencesMap()
{
Id(x => x.Id).GeneratedBy.Foreign("User");
Map(x => x.Name);
HasOne(x => x.User).Constrained();
}
}
. . , -- ...