Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hbulens/69fe51507a739e797d95474641954b62 to your computer and use it in GitHub Desktop.
Save hbulens/69fe51507a739e797d95474641954b62 to your computer and use it in GitHub Desktop.
public virtual IQueryable<TEntity> FindAll(Expression<Func<TEntity, bool>> where = null)
{
IQueryable<TEntity> query = where == null ? this.Context.Set <TEntity> () : this.Context.Set<TEntity>().Where(where);
var workspace = ((IObjectContextAdapter)this.Context).ObjectContext.MetadataWorkspace;
var itemCollection = (ObjectItemCollection)(workspace.GetItemCollection(DataSpace.OSpace));
var entityType = itemCollection.OfType<EntityType>().FirstOrDefault(e => itemCollection.GetClrType(e) == typeof(TEntity));
if (entityType != null)
{
foreach(var navigationProperty in entityType.NavigationProperties)
{
query = query.Include(navigationProperty.Name);
}
}
return query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment