简体   繁体   中英

How to use entity framework in business layer and/or data layer?

I would like to use entity framework in my asp.net application.

I can use Linq to entities in any layer, but I would like to know where should I put Entity Framework? (DAL, BAL or direct use in Presentation).

EntityFramework should go in the Data Access Layer. 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).

This is a one of the best practices that I have used for Entity Framework in data and business layers

1- In Data Layer

We will create a generic repository class for all required Entity Framework functions

2- In Business Layer

Now the Entity Framework is ready to use in Business Layer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM