Skip to content

Instantly share code, notes, and snippets.

@ucanbaklava
Created January 30, 2019 14:04
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 ucanbaklava/5f670697e500f5bf1be711d20e912dee to your computer and use it in GitHub Desktop.
Save ucanbaklava/5f670697e500f5bf1be711d20e912dee to your computer and use it in GitHub Desktop.
public virtual List<T> Get(Expression<Func<T, bool>> filter = null, Func<IQueryable<T>, IOrderedQueryable<T>> orderBy = null, params Expression<Func<T, object>>[] includes)
{
IQueryable<T> query = _context.Set<T>();
foreach(Expression<Func<T, object>> include in includes)
query = query.Include(include);
if (filter != null)
query = query.Where(filter);
if (orderBy != null)
query = orderBy(query);
return query.ToList();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment