Assume Entity
has columns SomeId, DateAt
of respective types int, DateTime
.
Let assume I have parameters collection:
{(SomeId_1, DateAt_1),...,(SomeId_N, DateAt_N)}
where 1=<N
I want to retrive all rows in Entity table that:
{r: (SomeId_1=r.SomeId AND DateAt_1=r.DateAt) OR .. OR (SomeId_N=r.SomeId AND DateAt_N=r.DateAt)}
Is there a way to write Linq query against DbSet?
_context.Entity....
that will produce query like:
SELECT *
FROM Entity
WHERE ( SomeId_1 = SomeId AND DateAt_1 = DateAt)
OR..
OR (SomeId_N = SomeId AND DateAt_N = DateAt)
How to achieve this using EF Core 3.1?
REMARK: Using code like below
List<EntityAtPait> pairs = ...
await _context.Entity.
.Where(f => pairs.Any(x =>
x.DateAt == f.DateAt
&& x.SomeId == f.SomeId ))
.ToListAsync())
throws:
System.InvalidOperationException: 'The LINQ expression 'DbSet<Entity>
.Where(f => ...
.Any(x => x.DateAt == f.DateAt && x.SomeId == f.SomeId ))' 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 either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.'