开发者

Breaking the dependency on Entity Framework

I have, what I think is a very well structured project, finally. After reading Fowler's onion architectu开发者_JAVA百科re, learning Ninject for IOC/DI and tweaking my Psuedo repository classes, I am using EF 4.1 so DbSet and DbContext supply the repository for the most part; I am now faced with the irritating dependency on Entity Framework when wanting to "Include" other Entities / Related Entities in my repository.

Does anyone have any suggestions on how to break this dependency? For example, I have a service layer that makes calls to Repository As soon as I decide to use .Include I am bound to the fat and heavy Entity Framework... Should I go with .Join or can EF be abstracted in some way?


Julie Lerman has a post on her blog where she shows an Include extension method on IQueryable<T>, which allows you to use Include in your code and not break your unit tests:

public static class MyExtensions
{
  public static IQueryable<TSource> Include<TSource>
    (this IQueryable<TSource> source, string path)
  {
    var objectQuery = source as ObjectQuery<TSource>;
    if (objectQuery != null)
    {
      return objectQuery.Include(path);
    }
    return source;
  }
}

See her full blog post here:
Agile Entity Framework 4 Repository Part 5: IObjectSet and Include

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜