Reputation: 647
I am using .NetCore2.0 and EntityFrameworkCore.
When I execute the following:
Expression<Func<Foobar, bool>> predicate =
x =>
query.Foos.Any(a => a.Contains(x.Foo)) &&
query.Bars.Any(s => s.Contains(x.Bar));
var results = GetAll().AsQueryable().Where(predicate);
I get the following warning messages in my console:
warn: Microsoft.EntityFrameworkCore.Query[200500] The LINQ expression 'Any()' could not be translated and will be evaluated locally. warn: Microsoft.EntityFrameworkCore.Query[200500] The LINQ expression 'where [a].Contains([x].Foo)' could not be translated and will be evaluated locally warn: Microsoft.EntityFrameworkCore.Query[200500] The LINQ expression 'where [a].Contains([x].Bar)' could not be translated and will be evaluated locally
The query itself does work and returns what I am looking for however I was wondering if there was a way to avoid these warnings or to suppress them
Upvotes: 1
Views: 3031
Reputation: 555
On our system, enabling this error was a deliberate decision on our part and was done by configuring the dbContextOptionsBuilder. I'll paste how we've turned it on so you can find where this must be in your system:
services.AddDbContext<FooContext>(options =>
options.UseSqlServer(BarConnectionString,
sqlServerOptions => sqlServerOptions.CommandTimeout(300)).UseLazyLoadingProxies()
.ConfigureWarnings(warnings =>
warnings.Throw(Microsoft.EntityFrameworkCore.Diagnostics.RelationalEventId.QueryClientEvaluationWarning))
);
Note that this is actually something useful as it's flagging that your query won't be entirely ran on the server so could be a performance problem.
Upvotes: 1