简体   繁体   English

我可以在实体框架中创建此配置吗?

[英]Can I create this configuration in Entity Framework?

So. 所以。 I create web-app with ASP.NET MVC wich helps 我使用ASP.NET MVC来创建Web应用程序

How could I create this databases in Entity Framework or should I change the concept? 如何在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

The idea is: I wish order two Pepperoni and Coke and my order will be saved as: 这个想法是:我希望订购两个意大利辣味香肠和可乐,我的订单将保存为:

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)

Is it possible to realise meal-order table with counter? 可以用柜台实现点菜桌吗? If it is very hard, could you propose another concept of tables for my database? 如果很难,您能为我的数据库提出表的另一种概念吗?

That's pretty much a classical Order - OrderDetail - Product model where your Meal is a Product and the MealOrder is an OrderDetail . 这几乎是经典的Order - OrderDetail - Product模型,其中您的MealProduct ,而MealOrderOrderDetail I would prefer to call the MealOrder entity/table OrderDetail because the fact that it has a reference to a Meal is perhaps only one of many attributes. 我希望将其称为MealOrder实体/表OrderDetail因为它可能引用了Meal ,但这可能只是许多属性之一。 For example, the OrderDetail might also have a Discount property that is not directly related to the meals but to the time when the order has been placed ("30 percent discount for all drinks on Mondays!"). 例如, OrderDetail可能还具有Discount属性,该属性与餐点不直接相关,而与下订单的时间直接相关(“星期一所有饮料都可享受30%的折扣!”)。

The entity model might look like this: 实体模型可能如下所示:

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
}

The database tables would be like sketched in your question. 数据库表就像您的问题中所概述的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM