What pattern should I use for data-access in case of VS2008 generated L2s or EF DataModels? Repository-pattern or what?
As we know VS2008 generates Data-Models and DataContexts/ObjectContexts in the same file, then, how should I arrange my VS2008 assemblies in my VS2008 solution to achieve a layered design?
If I use repository pattern, how should I arrange my assemblies in the VS2008 solution (as Data-Models and Data/Object-Contexts are stored in the same file…)?
Any web/example link would be appreciated.
What I’ve done is to wrap (in my case Linq2Sql) in my own custom class, which implements the repository pattern, here’s the pasted excerpt from a previous but somewhat related answer.
I’d recommend reading through The Onion Architecture and looking at the MVC StoreFront videos for inspiration. The magic part is, pushing the Linq2Sql part or EF stuff to one side, So you don’t sit on top of it as much as, Pull it in if you want it, that way you could use Linq2Sql or EF or NHibernate. This is more work, but gives you more flexibility.
Here’s my example CarProject
In Car.Core project
I then have a implementation of the interface which wraps up access to the generated Linq2Sql class.
Car.Data project
You could have a EF equivilent ofcourse, or NHibernate.
I haven’t got all this completely sorted, and I’m still learning but I currently have these projects:
In your scenario you could either put EF in Car.Data or maybe change it to Car.Linq2Sql and Car.EntityFramework. Not sure what I’d do.