简体   繁体   English

如何在业务层和/或数据层中使用实体框架?

[英]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.

相关问题 在单独的数据访问和业务逻辑层中,我可以在业务层中使用Entity框架类吗? - In separate data access & business logic layer, can I use Entity framework classes in business layer? 当使用实体框架作为数据访问层时,如何实现业务逻辑层? - How do you implement a business logic layer when using entity framework as data access layer? 如何从业务层使用实体框架更新实体? - How to update an entity using Entity Framework from Business Layer? 使用实体框架时,业务逻辑层中的数据对象 - Data Objects in Business Logic Layer when using Entity Framework 使用实体框架时如何创建 BLL(业务逻辑层)? - How to create BLL (Business logic Layer) when using Entity Framework? 实体框架 - 关于业务层需求的意见 - Entity Framework - Opinion on need of Business layer 具有服务层,业务层和实体框架的N层体系结构 - N-Tier Architecture with Service Layer, Business Layer, and Entity Framework 简单的数据操作:在实体模型还是业务层? - Simple data manipulation: in Entity Model or Business layer? OOP:仅在数据访问层中使用实体框架 - OOP: use Entity Framework only in the data access layer 最佳实践? 实体框架/ Linq2sql在业务层中的透明度 - Best Practice? Transparency of Entity Framework/Linq2sql in Business Layer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM