【发布时间】:2020-05-03 21:35:58
【问题描述】:
我正在制作一个商店项目。
我创建了一个产品类:
public Guid Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public string Description { get; set; }
public string PhotoUrl { get; set; }
public int Quantity { get; set; }
还有一个 Order 类:
public Guid Id { get; set; }
public List<Product> Products { get; set; }
public decimal TotalPrice { get; set; }
//address
public string Street { get; set; }
public string HouseNumber { get; set; }
public string PostCode { get; set; }
public string City { get; set; }
public Order()
{
Products = new List<Product>();
}
正如您在 Order.cs 中看到的,有一个产品列表,但实体框架始终在我的产品和订单之间设置关系,但我只想将产品添加到此列表中,而没有关系。 作为回应,我想得到这样的东西
{
"id" :"someID",
"products": [
{
first product
},
{
second product
}]
}
等等。如何防止通过 ef 关系创建并做简单的列表? 或者我怎样才能建立多产品与多订单的关系?
【问题讨论】:
标签: c# asp.net entity-framework entity-framework-core