David Veeneman
David Veeneman

Reputation: 19122

Organizing an EF4 data layer?

I am new to Entity Framework 4, and I am wondering, what's the best way to organize my data layer--the code that accesses EF4?

At this point, my data layer is set up like this:

Is there a better way to organize this functionality for EF4? I've looked for articles/blogs on the subject, but I'm not finding much. Any suggestions?

Upvotes: 2

Views: 298

Answers (2)

Dave Swersky
Dave Swersky

Reputation: 34810

I use a generic repository for Entity Framework that makes access very easy. No need to write a separate repository for each entity, just:

MyDataContext ctx = new MyDataContext();
Repository<MyEntity, MyDataContext > myEntityRep = new Repository<MyEntity, MyDataContext>(ctx);
myEntityRep.Add(new MyEntity() {//property settings});

This repository totally abstracts the Entity model, allowing for creating, modifying, and deleting entities.

Upvotes: 2

Florian Reischl
Florian Reischl

Reputation: 3856

I prefer the repository classes for each entity type (I know them as DataMapper). One class for all queries easily becomes too monolithic hard to maintain.

Upvotes: 1

Related Questions