score:2
The most likely reason for the discrepancy is that EF evaluates the first condition in memory, after retrieving all rows from RDBMS.
Microsoft documentation says the following about Client vs. Server Evaluation:
Entity Framework Core supports parts of the query being evaluated on the client and parts of it being pushed to the database. It is up to the database provider to determine which parts of the query will be evaluated in the database.
Your EF DB provider could not send scannerInput.Text.ToUpper()
to RDBMS for evaluation, so it did all comparisons in memory, after retrieving data rows from the database. This decision is correct, because EF DB provider cannot assume that consecutive evaluations of the above expression would yield identical results.
Second query, on the other hand, used a captured variable for the query. The value of that variable is guaranteed to stay constant while EF runs the query, so it proceeded to evaluating the request on the RDBMS side.
Source: stackoverflow.com
Related Articles
- string Text.ToUpper() slow inside of Linq query in C# Visual Studio 2017 ver 15.1.1
- Linq Query Formatting in Visual Studio
- Why doesn't Visual Studio 2010 allow the use of "is null" in a linq query when VS2017 does?
- Using Linq to query linked server in Visual Studio
- String comparison inside a LINQ query results in a nullable booelan?
- This linq query is going out of index after the Visual studio update
- Linq query string array inside List of strings
- How to convert an Int to a String inside a LINQ query
- LINQ Query from Object Array Inside Database column string
- Debugging Visual Studio Linq query in LinqPad
- LinqPad query runs fine, but fails with Linq to Entities error running in visual studio
- Visual Studio 2015 MySql LinQ to Entities Get generated query
- Calling a method inside a Linq query
- Convert datetime to a formatted string inside a LINQ-to-entities query
- How to OrderBy an integer in a string field in a Linq query
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Convert linq query to string array - C#
- Syntax to execute code block inside Linq query?
- Slow foreach() on a LINQ query - ToList() boosts performance immensely - why is this?
- Linq query to filter id inside a list of list c#
- Convert string to int in an Entity Framework linq query and handling the parsing exception
- Parse string into a LINQ query
- OData Linq to Query String
- Need to debug LINQ simple queries in Visual Studio 2010
- Nested Linq Min() crashes Visual Studio
- How to build a LINQ query from text at runtime?
- LINQ Query to Convert string to datetime
- Visual Studio Code Analysis Rule - "Do not expose generic lists"
- How can I sort a string of text followed by a number using LINQ
- convert string to DateTime in linq query with where clause?
- Filter List Data C#
- How to roll back queries in C#?
- Entity Framework & Oracle, Linq where clause string comparisons do not return any records if given a function parameter rather than a literal
- LINQ on List with lot of nested List
- Efficient way to be update grand child records in c# using LINQ
- VB.NET Date Comparison Not Returning Correct Results?
- Optimize Sitecore Lucene / Solr query
- CompilationErrorException when including System.Linq in Roslyn CP2
- LINQ to SQL Left Outer Join
- Linq order by boolean
- Linq with Different Where clauses and GroupBy
- INNER JOIN 3 Data Tables using LINQ
- Run an IQueryable with Entity Framework
- Casting a member access func from Func<DerivedFromT,object> to Func<T,object>
- Find the first matching string value in a list of objects
- Store multi-type OrderBy expression as a property
- how to convert list object to list string( getting error Unable to cast object of type)
- LINQ to List<KeyValuePair>
- Check if a table contains overlapping timespans
- Update fields in DB table by condition without loading