R – Fluent Nhibernate composed entity, specify foreign key

fluent-nhibernatenhibernatenhibernate-mapping

I have a Fluent Nhibernate map like :

 public class UserMap : ClassMap<PortalUser>
{
    public UserMap()
    {
        WithTable("aspnet_Users");
        Id(x => x.Id, "UserId")
            .GeneratedBy.Guid();
        Map(x => x.Name, "UserName");
        Map(x => x.Login, "LoweredUserName");
        WithTable("LdapUsers", m => m.Map(x => x.FullName, "FullName"));

    }
}

My foreign key column in table "LdapUser" is UserId but the select that gets generated is going to look for a "PortalUserId".
Is there a way to specify the relation key direcly?

Best Answer

Try this:

...
WithTable("LdapUsers", m => {
    m.Map(x => x.FullName, "FullName");
    m.WithKeyColumn("UserId");
});
Related Topic