开发者

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

开发者 https://www.devze.com 2023-04-02 00:02 出处:网络
public class AdminUser { publ开发者_如何学编程ic virtual int Id { get; set; } public virtual string UserName { get; set; }
public class AdminUser
{
    publ开发者_如何学编程ic 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?


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号