Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to brings the Entity Framework Include extention method to a Generic IQueryable<TSource>

Here's the thing.

I have an interface, and I would to put the Include extension method, who belongs to EntityFramework library, to my IRepository layer wich dont needs to knows about EntityFramework.

public interface IRepository<TEntity>
{
    IQueryable<TEntity> Entities { get; }

    TEntity GetById(long id);
    TEntity Insert(TEntity entity);
    void Update(TEntity entity);
    void Delete(TEntity entity);
    void Delete(long id);
}

So I have the extension method:

public static class IncludeExtension 
{
    static IQueryable<TEntity> Include<TEntity>(this IQueryable<TEntity> query, 
        string path)
    {
        throw new NotImplementedException();
    }
}

But I don't know how to implement it in this layer, and I would to send it to my EntityFramework (or whatever who will implement the IRepository) to deal with.

I need same to a Interface with a extension method.

Any light?

like image 575
iuristona Avatar asked Jul 22 '11 14:07

iuristona


1 Answers

Include is leaky abstraction and it works only with Entity framework. EF 4.1 already contains Include over generic IQueryable but it internally only converts passed generic IQueryable to generic ObjectQuery or DbQuery and calls their Include.

Here is some example how to wrap that include in repository (repository implementation is dependent on EF so it can use Include provided by EF directly).

like image 96
Ladislav Mrnka Avatar answered Oct 11 '22 19:10

Ladislav Mrnka