EF Core: Any reason to not throw on QueryClientEvaluationWarning

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


EF Core has a feature where it can evaluate parts of an query in memory when this part can not be executed on the DB. It logs a warning when this happens.

Optionally EF Core can be configured to throw an exception when that happens

        .ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning)); // <--

Since evaluating something in memory that the programmer intended to be executed in the DB can be a huge performance issue and is somewhat unclean imho I'm now thinking about using this exception configuration just everywhere and all the time.

I'm just wondering if there are any good reasons to not throw an exception? I personally would prefer an exception and then change the code to be executed intentionally in memory (e.g. with a .ToList() before the problematic statement). It's strange to me that EF would just work around a design flaw like that.

However I'm unsure if I'm forgetting any good reason why this exists in the first place or any situation where this might be necessary.

9/20/2019 9:09:39 AM

Accepted Answer

A good reason to not throw an exception is when you use a non-relational database and where you would have to do data processing and searching in your code. Another case can be if you use a linq query to combine data from multiple sources - in-memory data structure, XML, database, and you expect that you will only read from these sources and do all the processing in your code.

When you target relational databases only, however, you should always throw.

9/20/2019 9:17:40 AM

Related Questions


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