NHibernate:与关系表中字段的多对多关系 [英] NHibernate: Many-to-many relationship with field in the relationship table

查看:55
本文介绍了NHibernate:与关系表中字段的多对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在挠头.我有一个Car表和一个Customer表,它们之间具有多对多关系.在此关系表中,我想添加一栏来告诉我这是什么类型的关系.是顾客开车试驾,他想买车等吗?我要结束的是一个Car类类,其中包含客户关系信息的集合.我可能会以错误的方式看待这个问题,所以请随时向正确的方向推动我.

I'm scratching my head; I have a Car table and a Customer table that have a many-to-many relationship. In this relationship table I want to add a column that can tell me what kind of relationship this is; is the customer testdriving the car, do he want to buy the car, ect. What I want to end up with is a class Car object that holds a collection of Customers and the relationship information. I might be looking at this the wrong way so feel free to push me in the right direction.

推荐答案

我认为您缺少其他实体.您需要添加一个表达客户对汽车的兴趣的实体.您需要找到适合您业务领域的正确名称,但这是我的猜测:

I think that you are missing an additional entity. You need to add an entity that expresses the customer's interest in the car. You will need to find the right name to fit your business domain, but here is my guess:

您有CUSTOMER表来存储有关特定客户的信息. CUSTOMER与CUSTOMERINTEREST表具有一对多关系. CUSTOMERINTEREST存储有关客户从事的购物活动类型的信息(试驾,逛橱窗等). CUSTOMERINTEREST与CAR表具有多对一的关系. CAR在商店库存中存储有关特定汽车的信息.

You have CUSTOMER table to store information about a specific customer. CUSTOMER has a one to many relationship to the CUSTOMERINTEREST table. CUSTOMERINTEREST stores information about the kinds of shopping activities the customer is engaged in (test drives, window shopping, etc.). CUSTOMERINTEREST has a many to one relationship with the CAR table. CAR stores information about specific automobiles in the store's inventory.

因此,我最好的猜测是,如果关系中的事物需要的列多于两个外键,那么您实际上并没有多对多的关系.您有两个多对一的关系,而您还没有确定中间的东西.

So, my best guess is that if the thing in the middle of your relationship needs more columns than just the two foreign keys then you don't really have a many to many relationship. You have two many to one relationships and you just haven't identified the thing in the middle yet.

这篇关于NHibernate:与关系表中字段的多对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆