Combining a one-to-one relationship into one object in Fluent NHibernate
I have a one-to-one relationship in my database, and I'd like to just combine that into one object in Fluent NHibernate. The sp开发者_运维技巧ecific tables I am talking about are the aspnet_Users and aspnet_Membership tables from the default ASP.NET Membership implementation. I'd like to combine those into one simple User object and only get the fields I want.
I would also like to make this read-only, as I want to use the built-in ASP.NET Membership API to modify. I simply want to take advantage of lazy-loading.
Any help would be appreciated. Thanks!
How about using the Join
method of Fluent NHibernate to join the tables in your mapping. See James Gregory's answer in this question.
Here's my completed mapping:
public class UserMap : ClassMap<User>
{
public UserMap()
{
Table("aspnet_Membership");
Id(x => x.ID, "UserId");
Map(x => x.EmailAddress, "Email");
Join("aspnet_Users", m =>
{
m.KeyColumn("UserId");
m.Map(x => x.UserName);
});
}
}
精彩评论