Tutorial :what is the best practice approach for n-tier application development with entity framework?



Question:

I am building an application using entity framework. I am using the T4 template to generate self tracking entities.

Currently, I am thinking of creating the entity framework code in a separate project. In this same project, I would have partial classes with additional methods for the entities.

I am thinking of creating a separate project for a service layer (WCF) with methods for the upper/presentation tier. The WCF layer will reference the entity framework project. The methods in the WCF layer will return the entities or accept the entities as the parameters.

I am thinkg of creating a third project for the presentation layer (ASP.net), this will make calls to the WCF service but will also need to reference the entities as the WCF methods take these types as the parameters/return types.

In short, i want to use the STE entities generated by the T4 template as a DTO to be used in all layers.

I was originally thinking of creating a business logic layer that maps to each entities. Example: If i have a customer class, the Business Layer would have a CustomerBLL class and then methods in the customerBLL will be used by the service layer. I was also trying to create a DTO in this business layer. I however found that this approach is very time consuming and i do not see a major benefit as it would create more maintenance work.

What is the best practice for n-tier application development using entity framework 4?


Solution:1

You should separate your entities and their persistence logic into separate projects. That way your Presentation layer will only need to reference the project containing the entities and be persistence ignorant.

I guess the projects breakdown as the following would be a nice approach (at least it has worked out well for me :))

  • Entities in one project
  • Persistence logic in another project (Repositories, Unit of Work implementation)
  • WCF in one project
  • Presentation layer

Hope it helps.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »