views:

126

answers:

1

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

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

+5  A: 

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).

Furis
Should i create Business Objects and transform EF objects to BO objects and use them in BAL and presentation layer? Is this the only way?
Krunal
It is not the only way, but in my opinion it is the best way. It will help you reduce coupling, as well as help with the seperation of concerns. If you were to use EF objects on the BAL / Presentation layer, where would you put your business logic?
Furis
@Furis - Agreed, can you provide some sample code for one class.
Krunal
What section of code would you like a sample of? The transformation to a business object?
Furis
@Furis - Yes, if you explain the same thing with sample code that would be helpful.
Krunal
Ok, I will prepare a sample and post it a bit later.
Furis
@Furis - thanks.
Krunal
Here's a demo: http://blogs.teamb.com/craigstuntz/2009/12/31/38500/
Craig Stuntz
@Craig - nice link.
Krunal
Thanks Craig. @Krunal, sorry I didn't get around to posting the code sample, I had some difficulties accessing my SVN remotely.
Furis