DDD 和 MVC 模型保存单独实体的 ID 还是实体本身?
如果您有一个引用客户的订单,那么该模型是否包含客户的 ID 或客户对象的副本(如值对象)(考虑 DDD)?
我想这样做:
public class Order {
public int ID {get;set;}
public Customer customer {get;set;}
...
}
现在我这样做:
public class Order {
public int ID {get;set;}
public int customerID {get;set;}
...
}
将完整的客户对象包含在传递给表单的视图模型中比包含 ID 更方便。否则,我需要弄清楚如何将供应商信息获取到订单按 ID 引用的视图。
这也意味着存储库了解如何处理在调用保存时在订单对象中找到的客户对象(如果我们选择第一个选项)。如果我们选择第二个选项,我们将需要知道将其放置在视图模型中的位置。
可以肯定的是,他们会选择现有客户。然而,也可以肯定的是,他们可能想要更改显示表单上的信息。有人可能会争论让控制器提取客户对象,将客户更改单独提交到存储库,然后提交对订单的更改,同时将 customerID 保留在订单中。
If you have an Order that references a customer, does the model include the ID of the customer or a copy of the customer object like a value object (thinking DDD)?
I would like to do ths:
public class Order {
public int ID {get;set;}
public Customer customer {get;set;}
...
}
right now I do this:
public class Order {
public int ID {get;set;}
public int customerID {get;set;}
...
}
It would be more convenient to include the complete customer object rather than an ID to the View Model passed to the form. Otherwise, I need to figure out how to get the vendor information to the view that the order references by ID.
This also implies that the repository understand how to deal with the customer object that it finds within the order object when they call save (if we select the first option). If we select the second option, we will need to know where in the view model to put it.
It is certain they will select an existing customer. However, it is also certain they may want to change the information in-place on the display form. One could argue to have the controller extract the customer object, submit customer changes separately to the repository, then submit changes to the order, keeping the customerID in the order.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有以下模型:
和以下视图(来自
ViewPage
),您可以在视图中执行操作
,也可以
在控制器中执行操作,它将自动绑定
If you have the following model:
and the following view (from
ViewPage<Order>
)you can do in your view
but also
in your controller it will be bound automatically