[英]Entity Framework and Domain Layer
Design question on entity framework and Domain Layer - 有关实体框架和域层的设计问题-
I am creating a new application using the Entity Framework and the DTOs and Entity Objects would have the same structure but there would be quite a bit of business logic involved. 我正在使用实体框架创建新的应用程序,并且DTO和实体对象将具有相同的结构,但是会涉及很多业务逻辑。 So am wondering which would be the best approach from the following, considering the performance and maintainability of the application
因此,考虑到应用程序的性能和可维护性,我想知道以下哪种方法是最佳方法
Approach 1: 方法1:
Expose the Entity Objects to the UI Layer 将实体对象公开到UI层
Approach 2: 方法二:
I personally wouldn't put BL in my domain models or dtos. 我个人不会将BL放入我的域模型或dto中。 My controllers knows about my domain layer and also knows about a business layer.
我的控制器了解我的域层,也了解业务层。 My controllers ask/tell my BL to do work and domain models are returned.
我的控制器要求/告诉我的BL进行工作,并返回域模型。 Controller layer then maps domain model to dto and sends the dto to view.
控制器层然后将域模型映射到dto并将dto发送到视图。
In all the projects I have made I combined the two options. 在我所做的所有项目中,我都将两种选择结合在一起。 When using a grid with columns from 5-6 tables for example its easier to bind the columns to the properties of a Dto because you could avoid binding to subproperties.
例如,当使用具有5-6个表中的列的网格时,由于可以避免绑定到子属性,因此更容易将列绑定到Dto的属性。 It's also harder to create gridfilters if a object has to many subproperties.
如果对象具有多个子属性,则创建gridfilters也将更加困难。
So in case of data from multiple tables I guess its better to use Dto's 因此,对于来自多个表的数据,我想最好使用Dto的
If you have only data from one table I guess its a bit off overkill to create mappings between an Entity and a Dto with exact the same properties. 如果您只有一个表中的数据,我想在实体和Dto之间创建具有完全相同属性的映射会有些过分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.