views:

52

answers:

2

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 specific 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!

+1  A: 

How about using the Join method of Fluent NHibernate to join the tables in your mapping. See James Gregory's answer in this question.

LordHits
I added the join, but it doesn't seem to know how to relate the two tables. How can I modify which fields to join?
Mike C.
I was able to modify the KeyColumn in the join, and this works exactly how I want. Thanks for the help!
Mike C.
A: 

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);
            });
    }
}
Mike C.
Nice. Thanks for sharing.
LordHits

related questions