[英]How to use entity framework in business layer and/or data layer?
I would like to use entity framework in my asp.net application. 我想在我的asp.net应用程序中使用实体框架。
I can use Linq to entities in any layer, but I would like to know where should I put Entity Framework? 我可以在任何层的实体上使用Linq,但我想知道应该将实体框架放在哪里? (DAL, BAL or direct use in Presentation).
(DAL,BAL或在Presentation中直接使用)。
EntityFramework should go in the Data Access Layer. EntityFramework应该进入数据访问层。 To expose it up to the presentation layer tightly couples your presentation to the database, allowing changes at the database level to flow up to the presentation layer.
要将其显示在表示层上,会将您的表示紧密地耦合到数据库,从而使数据库级别的更改流到表示层。
What we have done on some of our projects is to use entity framework at the DAL, transform the entities to our business objects (which are actually quite simple object primarily used as DTO's as most of our logic is contained in services that act on the objects - this route isn't for everyone, but it fitted with what that architecht wanted). 我们在某些项目上所做的是在DAL使用实体框架,将实体转换为我们的业务对象(实际上是非常简单的对象,主要用作DTO,因为我们的大多数逻辑都包含在对对象起作用的服务中) -这条路线并不适合所有人,但符合Architecht的要求。
This is a one of the best practices that I have used for Entity Framework in data and business layers 这是我在数据和业务层中用于实体框架的最佳实践之一
1- In Data Layer 1-输入数据层
We will create a generic repository class for all required Entity Framework functions 我们将为所有必需的实体框架功能创建一个通用存储库类
2- In Business Layer 2-在业务层
Now the Entity Framework is ready to use in Business Layer 现在,实体框架已准备好在业务层中使用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.