NHibernate多对多关系表中的其他字段

时间:2022-10-04 10:50:01

when i have a many-to.many relation with nhibernate and let nhibernate generate my db schema, it adds an aditional table that contains the primary keys of the related entities. is it possible to add additional fields to this and access them without having to hassle around with sql manually?

当我与nhibernate有很多to.many关系并让nhibernate生成我的db模式时,它会添加一个包含相关实体主键的aditional表。是否可以向此添加其他字段并访问它们而不必手动使用sql麻烦?

3 个解决方案

#1


6  

I don't think thats possible. If you are saying that the relation has some state than in essence it is an object in it's own right and should be treated (mapped) as such.

我不认为这是可能的。如果你说这种关系有某种状态而不是本质上它本身就是一个对象,应该如此处理(映射)。

#2


0  

Agree with Jasper. What you are modeling in that case is not a relation but an entity itself, with 1-N and N-1 relations to the other two entities.

同意贾斯珀。在这种情况下,您建模的不是关系,而是实体本身,与其他两个实体具有1-N和N-1关系。

It is not that NHibernate cannot handle it, it is that you simply cannot model it.

并不是NHibernate无法处理它,而是你根本无法对其进行建模。

#3


0  

In this case, how would you build the in the mapping file for the new entity (that acts as the bridge between the two initial tables) ? In my case this link table has two foreign keys (int), one for each initial table, plus some other fields (startDate, endDate)

在这种情况下,您将如何在新实体的映射文件中构建(作为两个初始表之间的桥梁)?在我的例子中,这个链接表有两个外键(int),每个初始表一个,加上一些其他字段(startDate,endDate)

The thing is, in my new entity, I do not have properties for these two foreign keys. I only have one property that is of the type of the entity the foreign key is pointing to.

问题是,在我的新实体中,我没有这两个外键的属性。我只有一个属性是外键指向的实体的类型。

#1


6  

I don't think thats possible. If you are saying that the relation has some state than in essence it is an object in it's own right and should be treated (mapped) as such.

我不认为这是可能的。如果你说这种关系有某种状态而不是本质上它本身就是一个对象,应该如此处理(映射)。

#2


0  

Agree with Jasper. What you are modeling in that case is not a relation but an entity itself, with 1-N and N-1 relations to the other two entities.

同意贾斯珀。在这种情况下,您建模的不是关系,而是实体本身,与其他两个实体具有1-N和N-1关系。

It is not that NHibernate cannot handle it, it is that you simply cannot model it.

并不是NHibernate无法处理它,而是你根本无法对其进行建模。

#3


0  

In this case, how would you build the in the mapping file for the new entity (that acts as the bridge between the two initial tables) ? In my case this link table has two foreign keys (int), one for each initial table, plus some other fields (startDate, endDate)

在这种情况下,您将如何在新实体的映射文件中构建(作为两个初始表之间的桥梁)?在我的例子中,这个链接表有两个外键(int),每个初始表一个,加上一些其他字段(startDate,endDate)

The thing is, in my new entity, I do not have properties for these two foreign keys. I only have one property that is of the type of the entity the foreign key is pointing to.

问题是,在我的新实体中,我没有这两个外键的属性。我只有一个属性是外键指向的实体的类型。