问题描述
创建新应用时遇到问题。该应用程序是关于在特定日期进入的新员工的。由于他们需要一些硬件(例如笔记本电脑,键盘等),因此我们希望提供有关未来几天将要出现的所有新员工的概述。
I ran into a problem when creating a new app. The app is about new employees that enter on a specific date. As they need some Hardware (such as Notebooks, keyboards etc.) we want to provide an overview over all the new employees that are going to come in the next few days.
因此有以下模型:
条目:
public class Entry{
public IEnumerable<Hardware> Hardware {get; set;}
...
}
硬件:
public class Hardware{
public string Name {get; set;}
public OrderStatus Status {get; set}
}
OrderStatus:
OrderStatus:
public enum OrderStatus{
Nothing,
Ordered,
Arrived,
Ready
}
起初这看起来不错,因为我想为每个条目创建一个新的硬件数据集(一对多)。现在,我决定维护一个硬件列表,仅将硬件引用到该条目(很多到很多)。问题是OrderStatus绑定到硬件,因此当一个硬件引用到许多员工并且Orderstatus更改时,它将在所有条目上更改。
At first this seemed fine because for every entry I wanted to create a new Hardware dataset (one to many). Now I decided to maintain a list of Hardware and just reference the Hardware to the Entry (many to many). The problem is that the OrderStatus is bound to the Hardware so when one Hardware is referenced to many Employees and the Orderstatus gets changed it will be changed on all entries.
我认为正确的解决方案是使用第三个表(Entry_Id,Hardware_Id,OrderStatus)。使用流畅的API,可以在新的(第三个)表中映射关系,但无法向其中添加新的属性(OrderStatus)。
I think the proper solution would be to use a third table (Entry_Id, Hardware_Id, OrderStatus). With fluent API it's possible to map a relationship in a new (third) table but it's not possible to add a new property (OrderStatus) to it. Is this even possible?
推荐答案
根据此:
有关更多详细信息,请参阅链接的答案。
Please refer to the linked answer for more details.
这篇关于使EF使用具有附加属性的m:n表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!