Fluent Nhibernate composed entity, specify foreign

2019-09-19 02:16发布

问题:

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?

回答1:

Try this:

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