Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET and Entity Framework in Layered Architecture - using Entity Framework for ORM only

I have an ASP.NET application that uses a layered architecture e.g. presentation layer, business logic layer, data access layer.

I don't want to the business layer to have to know anything about how the data access layer is implemented and I'm not looking to bind the Entity's directly to a data control using the EntityDataSource or anything like that. (so a repository pattern scenario)

I'M JUST LOOKING TO USE THE ENTITY FRAMEWORK AS AN ORM TOOL TO GENERATE CLASSES. I know how to do this. What I'm not clear on is

  1. Is it advisable to propagate these classes up through the application so the business logic layer would be dealing with the partial classes created directly by the entity framework? (for instance if I have a customer table in sql, the entity fw would created a customer class which could potentially be used directly in all layers of my app)
  2. How to manage transaction support if my BLL is calling several different entity classes but wants to treat it as one transaction
like image 329
AJM Avatar asked May 27 '09 12:05

AJM


3 Answers

  1. If you are practical: Yes! It will avoid you double mapping work and the potential errors generated by the double mapping. (By double mapping I mean DB -> ORM and ORM -> Business logic).
  2. Use TransactionScope. It's the best way to do transaction without worrying about nested transactions.
like image 91
Eduardo Molteni Avatar answered Nov 17 '22 07:11

Eduardo Molteni


I suspect that this may be the answer to your problem:

http://code.msdn.microsoft.com/EFPocoAdapter/Release/ProjectReleases.aspx?ReleaseId=1580

The tool generates classes that have no entity framework dependency that you can pass across tiers.

like image 3
RobD Avatar answered Nov 17 '22 06:11

RobD


Another way to do this is to use mapper classes, use what EF purely as data access and use the classes EF generated only within the DAL, then map these DAL objects to your BLL's objects through mappers. It works fine for us.

like image 2
Ray Avatar answered Nov 17 '22 08:11

Ray