Entity Framework and Three-Layer Architecture

I have a three layer architecture. Questions:
1. Is data access an EF layer?
2. If I want to use an entity generated by EF from the presentation layer, then I refer to Data Access, but this violates the principles of a 3-tiered architecture.

+4
source share
5 answers

Yes, EF will be your level of data access. With EF, you can use T4 templates with POCO support, you can extract these POCOs into a separate dll, and this will be a link from all your layers.

+1
source

Microsoft Spain has released pretty good documentation, a guide and sample application for N-tiered codeplex applications, you can see here:

http://microsoftnlayerapp.codeplex.com/

Here you will find many directions and useful implementation templates.

NTN.

+2
source

What type of application are you building? If you are creating an ASP.NET MVC 3 application, you can specify that your view will be displayed, your model is your data access (which can use EF), and the controller and / or action filters can contain your business logic in In this scenario, you will use your EF model in the presentation layer, but still satisfy the principle of separation of concerns.

+1
source

EF does two things: -

1) Creates a domain model for you (optional, but usually used) 2) Provides you with the ability to query / modify your database using this domain model.

This can blur the lines between the domain model and data access, but the two are really separate.

As long as you do not do such things as creating contexts of objects and recording queries directly in your tierthen IMHO presentation, you do not violate abstractions - the only thing you β€œbroke up” is that you will need to reference System.Data .Objects (or something like EF dll) in your presentation project (s) (which is just a physical artifact) if you don't go down the route suggested by Jethro to create your domain model in a separate project.

+1
source

For three-tier architecture. I would think of doing an abstraction using a domain model model and a data model, and then doing direct EFs from the presentation layer.

So the idea is that you have a data model that has EF POCO classes with repositories that know how to access these classes for different CRUDs.

Your domain model will have models associated with your client (so that you can put various ViewModels or verification-related code), it can be a WPF or MVC web application. Now there is a business between the two that is talking to both Domain models and data.

Your presentation level knows nothing about EF / Layer / Repository. When you want to implement a new database or database, you just need to write new repository classes and data model classes (which may be with some kind of gen code).

It also allows your module to be testable.

0
source

All Articles