inutan
inutan

Reputation: 10888

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

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!

Upvotes: 0

Views: 498

Answers (1)

anivas
anivas

Reputation: 6547

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

Upvotes: 2

Related Questions