繁体   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