我们是否需要在 Order 模型类中同时拥有 Customer 属性和 CustomerId 属性?
我对实体框架和基于数据的应用程序非常陌生。
让 Customer
数据模型类如下:
public class Customer
{
public int CustomerId {get;set;}
public string Name {get;set;}
//others properties have been omitted for the sake of simplicity.
}
和 Order
数据模型:
public class Order
{
public int OrderId {get;set;}
public int CustomerId {get;set;}
public Customer Customer {get;set;}
// other properties have been omitted for the sake of simplicity.
}
我的问题是:“我们是否需要一起使用 Customer
的属性在 Order
模型类中具有 CustomerId
属性?”
I am very new to Entity Framework and data-based application.
Let the Customer
data model class be as follows:
public class Customer
{
public int CustomerId {get;set;}
public string Name {get;set;}
//others properties have been omitted for the sake of simplicity.
}
And the Order
data model:
public class Order
{
public int OrderId {get;set;}
public int CustomerId {get;set;}
public Customer Customer {get;set;}
// other properties have been omitted for the sake of simplicity.
}
My question is: "Do we need a property of Customer
together with a property of CustomerId
in Order
model class?"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,你不知道。
Order
类中的Customer
对象足以识别客户 ID。此外,您可能需要Customer
类中的订单集合,以便您轻松了解客户有多少个订单,如下所示:-因此,如果您想从订单中检索客户 ID ,你会做这样的事情:-
No, you don't. The
Customer
object inOrder
class is sufficient to identify the customer ID. Further, you might want a collection of orders inCustomer
class, so that you know how many orders the customer has easily, something like this:-So, if you want to retrieve the customer ID from an order, you will do something like this:-