Reputation: 12413
With DataContext I could do something like
public IQueryable<T> All()
{
return db.CreateObjectSet<T>().AsQueryable();
}
(as part of a generic repository class - the rest of the CRUD actions are handled in a similar manner)
I'm looking to see if the same is possible with DbContext : i.e. can a return a Queryable of T? Entry looks a bit like it might help, but not quite... ideas anyone ?
Upvotes: 1
Views: 1848
Reputation: 623
If you wish to return a Queryable would be something like:
public virtual IQueryable GetAll()
{
return dbContext.Set<T>();
}
In fact, I blogged some time ago about how to create a generic repository using EF4.1 take a look:
http://davidandersonlino.net/blog/2011/04/28/generic-repository-pattern-com-entity-framework-4-1/
Hope I answered your question.
Upvotes: 3
Reputation: 7095
DbSet
implements IQueryable
this should work:
public IQueryable All()
{
return db.Set<T>();
}
Upvotes: 4