流畅的Nhibernate组成实体,指定外键

时间:2009-04-28 09:12:41

标签: nhibernate fluent-nhibernate nhibernate-mapping

我有一个流利的Nhibernate地图,如:

 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"));

    }
}

表“LdapUser”中的外键列是UserId,但生成的选择将查找“PortalUserId”。
有没有办法直接指定关系键?

1 个答案:

答案 0 :(得分:2)

试试这个:

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