I'm using EFCore 2.2.3 and I have disabled local evaluation.
I have the following queries
var query1 = companyContext.Companies.Where(c => c.Name == name);
var query2 = companyContext.Companies.Where(c => c.Id == 10);
If i execute them on their own they work correctly.
await query1.ToListAsync();
await query2.ToListAsync();
But if i try to
var result = await query1.Union(query2).ToListAsync();
i get the following error:
InvalidOperationException: Error generated for warning 'Microsoft.EntityFrameworkCore.Query.QueryClientEvaluationWarning: The LINQ expression 'Union({from Company c in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[MagliteTest.Database.Company]) where ([c].Id == 10) select [c]})' could not be translated and will be evaluated locally.'. This exception can be suppressed or logged by passing event ID 'RelationalEventId.QueryClientEvaluationWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
Is union not supported on entity framework core?
q1.Union(q2).Where(x => ...)
and the union part translated to a very expensive-to-execute query (many 10s of 1000s of rows, which the condition then filtered out). In the end I had to doq1.Where(x => ...).Union(q2.Where(x => ...))
after trying various solutions likeid in q1 OR id in q2
that I couldn't get to work.