Domanda

I just want to know if this is possible to do with fluent nhibernate.

I got a self reference table in my database.

Table Service
{
int Season (PK) (FK)
int Service_No (PK)
int ParentService_No (FK)
}

The table has a composite key as Season and Service_No, and Foreign Key for Self Reference as Season and ParentService_No

I try to create a collection property called ChildServices in my Service Class as many to many relations.

HasManyToMany(x => x.ChildServices )
.Table("SERVICE")
.Access.Property()
.AsBag()
.Cascade.SaveUpdate()
.LazyLoad()
.Generic()
.ParentKeyColumns.Add("SEASON")
.ParentKeyColumns.Add("SERVICE_NO")
.ChildKeyColumns.Add("SEASON")
.ChildKeyColumns.Add("P_SERVICE_NO");

If I use above mapping, it will throw my exception saying Repeated column in mapping for collection: Service.ChildServices column: SEASON

How can I do this? Is this a limitation of fluent nhibernate?

Thanks for answering my question.

È stato utile?

Soluzione

this is a limitation of NHibernate. You can not use one column for two different things for example in your case primary key and foreign key. see my question on the same subject

you could try to guess NHibernate's generated alias and use the ParentService_No column as foreignkey and a where condition with the alias on the service_no

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top