Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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