Microsoft.EntityFrameworkCore.Query Warning when running query

asp.net-core-2.0 c# entity-framework-core

Question

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

1
1
9/12/2017 12:03:27 PM

Popular Answer

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.

0
10/15/2019 4:06:48 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow