Fluent NHibernate: How to create circular one-to-one mapping?

╄→гoц情女王★ 提交于 2020-01-05 03:33:45

问题


public class AdminUser
{
    public virtual int Id { get; set; }
    public virtual string UserName { get; set; }
    public virtual string Password { get; set; }
    public virtual bool IsLocked { get; set; }
    public virtual AdminUser Creator { get; set; }
    public virtual DateTime CreationDate { get; set; }
}

public class AdminUserMapping : ClassMap<AdminUser>
{
    public AdminUserMapping()
    {
        Id(c => c.Id).GeneratedBy.Native();
        Map(c => c.UserName).Not.Nullable();
        Map(c => c.Password).Not.Nullable();
        Map(c => c.IsLocked).Not.Nullable();
        Map(c => c.CreationDate).Not.Nullable();
        //HasOne<AdminUser>(... ?) 
    }
}

Hi i have class like above, and i want to create one-to-one mapping for "Creator" property on same class

how can i do this?


回答1:


Try this:

References(x => x.Creator);

Make sure that you have a column named Creator_Id on your table. If you don't, you can use:

References(x => x.Creator).Column("YourColumnName")


来源:https://stackoverflow.com/questions/7255950/fluent-nhibernate-how-to-create-circular-one-to-one-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!