0

I'm trying to develop a generic repository on Entity Framework 5 for get data from any table and I want to use disconnected context without lazy and eager loading. Is it possible? I'm using the code below, but it doesn't works:

T it's entity type.

public IList<T> GetData(Expression<Func<T, bool>> expression)
{
        using (var context = new Context())
        {
            return context.Set<T>().Where(expression).ToList();
        }
}

Just the main entity it's loaded, the relationships no.

deverton
  • 31
  • 4
  • "I want to use disconnected context without lazy and eager loading" - not quite sure what you mean, you can only have one or the other. – Rocklan Oct 16 '13 at 04:49
  • Generic repository - [why](http://stackoverflow.com/q/12338068/861716)? You're running into the first of many obstacles. You've got to parametrize the `Include` statement in a generic way. Not nice. – Gert Arnold Oct 16 '13 at 18:21
  • @Gert Arnold, use `Include` statement in a generic way is my problem. So, the question is: Is it possible to load entities and your relationships without lazy load and without `Include` statement in a generic repository? **Why no use a generic repository for CRUD basic operations?** – deverton Oct 26 '13 at 14:22
  • Because generic repositories tend to become nothing but thin wrappers around `DbSet`s. Composite CRUD operations tend to become more convoluted, and why use a layer for basic operations and another one for more complex ones? Anyway, it's your call. You can add an `IEnumerable` argument to specify `Include`s, or `IEnumerable>>` and add the `Include`s to the Set in a `foreach` loop. – Gert Arnold Oct 26 '13 at 19:29

0 Answers0