【发布时间】:2019-07-11 07:27:34
【问题描述】:
我创建了一个应用程序,作为测试示例,我使用了一张订单表。我对类建模有疑问。
我有 3 个课程:
public class Car
{
public int Id { get; set; }
public string Name { get; set; }
public double Price { get; set; }
}
public class Part
{
public int Id { get; set; }
public string Name { get; set; }
public double Price { get; set; }
}
class Order
{
public Order()
{
Cars = new List<Car>();
Parts = new List<Part>();
}
public int OrderId { get; set; }
public int CarId { get; set; }
public int PartId { get; set; }
public ICollection<Car> Cars { get; set; }
public ICollection<Part> Parts { get; set; }
}
不知道这个型号好不好。你怎么看?因为这里没有东西:/在应用程序中:
我无法将汽车或零件添加到数据库中没有的订单中。
-
在订单表中,我只想查看订单 ID、订单价值、汽车 ID 和所购买零件的 ID。
我希望 Car 和 Part 表中没有关于订单的数据。我只想在应用程序中添加零件或汽车,以后只能在订单部分从中选择。
【问题讨论】:
-
一个订单可以只包含一个汽车和单个零件,还是同一订单中包含多个汽车和零件?就目前而言,您订购的课程正在向 EF 提供相互矛盾的信息。
-
@LorenPaulsen 订单可能很少有汽车和零件。
标签: c# entity-framework ef-code-first code-first