流利的 NHibernate,多对多,从多对多表中为子对象设置属性
我有一个 Subscriber
对象,其中包含 Provider
对象列表。提供者可以属于多个订阅者,因此存在多对多关系。这很好,除了 Provider
需要定义一个 Status
属性,但这不能存储在 Provider
表中,因为同一个提供程序可以不同的订阅者有不同的Status
,因此我将Status
存储在多对多表中。目前我有一个基本的多对多映射:
HasManyToMany(s => s.Providers)
.Table("SubscriberProviders")
.ParentKeyColumn("SubscriberID")
.ChildKeyColumn("ProviderID");
如何在多对多映射中设置 Provider
的 Status
属性?
非常感谢
I have a Subscriber
object that contains a list of Provider
objects. Providers can belong to many Subscribers, hence the many-to-many relationship. This is fine, except that the Provider
needs to define a Status
property but this cannot be stored in the Provider
table, as the same provider could have a different Status
for different Subscribers, so I am storing the Status
in the many-to-many table. At the moment I have a basic many-to-many mapping:
HasManyToMany(s => s.Providers)
.Table("SubscriberProviders")
.ParentKeyColumn("SubscriberID")
.ChildKeyColumn("ProviderID");
How can I set the Status
property, of the Provider
, within the many-to-many mapping?
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
多对多
映射不能拥有自己的属性,因此您必须将联接表映射到人工 ProviderSubscriber 实体,该实体将是来自提供商的一对多
。有关解决方法的完整示例,请参阅 多对-与属性的许多关系
A
many-to-many
mapping can't have properties of its own, so you have to map the join table into an artificial ProviderSubscriber entity, which will beone-to-many
from the Provider.For a full example of a workaround, see Many-to-many relationships with properties
您必须映射交叉引用表(NH 当前为您生成),并将提供者和订阅者之间的映射更改为引用交叉引用表的任一侧的 HasMany()。
You'll have to map the cross-reference table (which NH currently generates for you), and change the mapping between Providers and Subscribers to instead be a HasMany() on either side referencing the cross-reference table.