I need to have a method like this, where I can apply Where(x =>x. ...) and Include(x => x.RelatedEntity) and OrderBy(x=>x. ...) on a given entity.
Something like this:
public List<TEntity> ApplyFilter<TEntity>(TEntity entity,
List<filters> filters /* List of filters: 'filters' */)
where TEntity : BaseEntity
{
using (var db = new MyDbContext()){
var query = db.Set<TEntity>().AsQueryable;
//apply filters to 'query'
query.include(/*multiple related entities*/);
query.applyfilters(/*filters*/);
return query.ToList();
}
}
And I need to pass what I need to be filtered/included as lambda expressions.
NOTE: I searched a lot about how I can do it but I really wasn't able to find anything. I'm new to this part of C# / Entity Framework and I really didn't even know what keywords to search for.
Thank you for the help