Cześć,
chciałem zrobić sobie generyczną metodę do pobierania danych:
public async virtual Task<List<TValue>> GetAsync<TKey, TValue>(ICollection<TKey> id)
where TKey : struct
where TValue : class, IReferenceType<TKey, TValue>
{
if (id == null || id.Count == 0)
{
return new List<TValue>();
}
List<TValue> items = await _dataContext.Set<TValue>().Where(w => id.Contains(w.GetReferenceKey())).ToListAsync();
return items;
}
Ale jak używam Contains to dostaje:
The LINQ expression 'DbSet<Operator>()
.Where(o => __id_0.Contains(o.GetReferenceKey()))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
zwykłego == też nie mogę użyć bo otrzymuje:
Operator '==' cannot be applied to operands of type 'TKey' and 'TKey'
Jak mogę rozwiązać ten problem?
Obstawiam że przez to ze obiekt implementuje IReferenceType który zwraca PK, to przy użyciu GetReferenceKey() EF nie wie na którą kolumnę ma nałożyć warunek.