簡體   English   中英

我可以在實體框架中創建此配置嗎?

[英]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模型,其中您的MealProduct ,而MealOrderOrderDetail 我希望將其稱為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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM