views:

208

answers:

4

What is alternative patterns of using for Entity Framework ?

Some I know are:

  1. "Plain" EntityFramework - aka Unity of Work

    using (Data.Model c = new Data.Model())
    {
        var z = c.Users.Where(x=>x.Name=='John');
    }

  2. Repository pattern

    //Model implements IRepository
    User user = Model.Instance.Get<User>(u => u.Name == "John");
    

  3. What else ?
  4. ?
A: 

We use code similar to what you have in your unit of work example.

What we do in addition is to map objects to Data Transfer Objects.

Shiraz Bhaiji
+1  A: 

A good book to look at is Martin Fowler's "Patterns of enterprise application architecture".

There he goes through some patterns for retrieving/mapping data like DTOs, Unit of work, repository pattern etc... Maybe something could be useful together with the Entity Framework. I'd have to take a look at it.

Juri
A: 

There are many articles on the subject, but the list will be reduced substantially if you'd like a good one. This article from MSDN Magazine is pretty good, although it deals specifically with n-tier applications. But since you don't say what you're building, maybe it will help.

Craig Stuntz
A: 

LINQ 2 SQL can be an alternative. Here is an article Dependency Injection with Unity and Linq to SQL DataContexts

UNITY - http://unity.codeplex.com/

Bogdan_Ch