开发者

Fluent Nhibernate - One to Many Mapping - Child of same type as Parent

开发者 https://www.devze.com 2023-03-19 09:47 出处:网络
I have a class defined as: public class ReportClient { public virtual int? Id { get; set; } public virtual long? ClientId { get; set; }

I have a class defined as:

public class ReportClient
{
    public virtual int? Id { get; set; }

    public virtual long? ClientId { get; set; }

    public virtual 开发者_开发百科string Name { get; set; }

    public virtual string EmailAddress { get; set; }

    public virtual string AdditionalEmailAddress { get; set; }

    public virtual List<ReportClient> ChildClients { get; set; }
}

As you can see ChildClients are of same type as Parent.

Please guide me how can I map 'ChildClients' so for each ChildClient in List<ReportClient> ChildClients there is a new table record with a column 'ParentId' being set for this record ( having ParentId = Id)

Please guide.

Thank you!


I don't have the enviroment to test, but this should work, try swapping the column names if it doesn't.

  HasManyToMany(x => x.ChildClients)
    .ParentKeyColumn("ParentId")
    .ChildKeyColumn("Id") 
0

精彩评论

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