Skip to content

Instantly share code, notes, and snippets.

@oneillci
Created July 30, 2012 06:45
Show Gist options
  • Save oneillci/3205384 to your computer and use it in GitHub Desktop.
Save oneillci/3205384 to your computer and use it in GitHub Desktop.
Using EF Include() with generic repository
public IQueryable<T> FindBy(Expression<Func<T, bool>> predicate, params Expression<Func<T, object>>[] includes)
{
var query = GetAll().Where(predicate);
return includes.Aggregate(query, (current, includeProperty) => current.Include(includeProperty));
}
// Sample usage
userRepository.FindBy(x => x.Username == username, x.Roles)
@subinbab
Copy link

subinbab commented Apr 2, 2022

How Can I get multiple navigation property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment