user1288058
user1288058

Reputation: 183

Full encapsulation of the Entity Framework

I'm developping a line of business application using WPF as a presentation layer (of course with MVVM).

I'm using ADO.Net Entity Framework to map the DataBase.

I don't want to use entities directly in code (in the business layer). I want to separate my project into 3 layers:

According to this post I want to implement a full encapsulation of the Entity Framework to provide a separation of concerns and to not be dependant on EF as ORM in the future.

Can you help me by giving me some exemples to encapsulate the EF and how to implement this in code.

Upvotes: 3

Views: 2748

Answers (3)

Maverick
Maverick

Reputation: 93

There is one way of doing it, using POCO. Entity Framework 4.0 comes with the support of POCO (Plain CLR Objects). But POCO has its own complexities, when u have to deal with Relationship and associations. You can refer to the blog by Julie Lerman (a nice article)

http://thedatafarm.com/blog/data-access/agile-entity-framework-4-repository-part-1-model-and-poco-classes/

Upvotes: 0

sebagomez
sebagomez

Reputation: 9599

I would take a look at this post wich implements UnitOfWork and Repository patterns to implement what, I understand, you want to achieve.

http://blogs.msdn.com/b/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx

Upvotes: 0

J.W.
J.W.

Reputation: 18181

Regarding this

I want to implement a Full encapsulation of the Entity Framework. to provide a separation of concerns and to not be dependant on EF in the future as ORM

Normally, you will create yourself a lot of problems if you go that route. If you choose EF, you really should make full use of the features, not hiding that behind another abstraction.

EF itself is already an abstraction layer over DB, there is no need to create another abstraction on top of that.

Upvotes: 10

Related Questions