I am using a repository pattern that returns back IEnumerables with Entity Framework Core 2 and would like to implement a get method that takes a comma delimited string of column names and returns back a list of entities with only those columns. I want to limit the amount of data that comes from the DB (nice to have) but more importantly I need to limit the amount of data that goes from the REST api to the browser.
It looks like the nuget package EntityFramework.DynamicLinq is the way to go. Best as I can tell from the documentation at Github Link.
I should be able to do this:
using EntityFramework.DynamicLinq
public class CompanyRepository
{
public async Task<IEnumerable<Company>> Get(string columns)
{
return await _dbSet.AsNoTracking().Select("new(" + columns + ")").ToListAsync();
}
}
Unfortunately that gives the following error for the Select call:
The type arguments for method
Enumerable.Select<TSource, TResult>(IEnumerable<TSource>, Func<TSource, TResult>)
cannot be inferred from the usage