[英]Can I create this configuration in Entity Framework?
所以。 我使用ASP.NET MVC來創建Web應用程序
如何在Entity Framework中創建此數據庫,或者應該更改概念?
TABLE order //Table for orders
Id int,
Person nvarchar(50),
TABLE meal //List of meals
Id int
Description nvarchar(50)
TABLE meal-order //Many-to-one table with count of meals
IdOrder int,
IdMeal int,
Count tinyint
這個想法是:我希望訂購兩個意大利辣味香腸和可樂,我的訂單將保存為:
TABLE order
orderId, My Name
TABLE meal (it has some stuff)
pepperoniId, Pepperoni
cokeId, Coke
hotDogId, Hot Dog
TABLE meal-order
orderId, pepperoniId, 2 (and here 2 is count of pepperoni I ordered)
orderId, cokeId, 1 (just one coke)
可以用櫃台實現點菜桌嗎? 如果很難,您能為我的數據庫提出表的另一種概念嗎?
這幾乎是經典的Order
- OrderDetail
- Product
模型,其中您的Meal
是Product
,而MealOrder
是OrderDetail
。 我希望將其稱為MealOrder
實體/表OrderDetail
因為它可能引用了Meal
,但這可能只是許多屬性之一。 例如, OrderDetail
可能還具有Discount
屬性,該屬性與餐點不直接相關,而與下訂單的時間直接相關(“星期一所有飲料都可享受30%的折扣!”)。
實體模型可能如下所示:
public class Order
{
public int Id { get; set; }
public string PersonName { get; set; } // the "Customer"
// ... more properties
// an order has many OrderDetails/meals
public virtual ICollection<OrderDetail> Details { get; set; }
}
public class OrderDetail // your "order-meal"
{
public int Id { get; set; }
public int OrderId { get; set; }
public virtual Order Order { get; set; }
public int MealId { get; set; }
public virtual Meal Meal { get; set; }
public int Quantity { get; set; } // your Count
// ...more properties like for example decimal Discount
}
public class Meal // the "Product"
{
public int Id { get; set; }
public string Description { get; set; }
// ...more properties
}
數據庫表就像您的問題中所概述的那樣。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.