I have this model in my DB, and specific classes to represent it in ef core.
I am using GenericRepository and trying to get a collection of DietProduct table which later would be adapted by auto mapper for a view.
The problem starts when I try to get the list of all active DietProducts with DietproductLocalization where LanguageId = @LanguageId;
I tried to complete a generic method like this:
public List<TEntity> FindComplex(Expression<Func<TEntity, bool>> predicate, params string[] includes)
{
IQueryable<TEntity> query = Context.Set<TEntity>();
foreach (var include in includes)
query = query.Include(include);
return query.Where(predicate).ToList();
}
and then use the select as:
int currentLanguage = LanguageUtility.GetLanguageId(CultureInfo.CurrentCulture);
var dp = _repo.DietProduct.FindComplex(x => x.Active
&& x.DietProductLocalization
.Any(l => l.LanguageId == currentLanguage), "DietProductLocalization");
but no luck so far, because it keeps returning all the rows from included table, of course as include stands for all or nothing.
Is there any way to write the generic method and specific query so I don't have to use specific queries with inner joins all over?