Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save uzbekdev1/0f9b4530a0ca97b6aba5e8e830e61edc to your computer and use it in GitHub Desktop.
Save uzbekdev1/0f9b4530a0ca97b6aba5e8e830e61edc 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment