score:9
the difference is that in the first case, var
will be an iqueryable<t>
- which means your where
call will be to queryable.where
(after converting your lambda expression to an expression tree). the filter ends up being executed in the database, where i suspect your field is case-insensitive (and so searching is case-insensitive).
in the second case, you've got an ienumerable<t>
, so your where
call will be to enumerable.where
(after converting your lambda expression to a delegate). the filter ends up being executed in .net code instead - where contains
is always case-sensitive.
basically, linq is a leaky abstraction - yes, it would be lovely if the same filter gave the same results in all situations, but that's unrealistic. learn where the leaks are, and act accordingly - linq is still a huge boon :)
score:7
your result
variable is not an ienumerable
- it is an iqueryable
.
the result is changing when you manually change the type to ienumerable
since you now do the following contains
query with linq to objects and not on the database with linq to entities (or linq to sql).
with ienumerable
your query is using your lambda expression, bringing each result from the db into memory and executing the case sensitive contains()
extension method.
with iqueryable
your query is using an expression tree and will try to create a corresponding database query with your contains
query which happens to be case insensitive (most likely a sql like
query).
just making the implicit type explicit as iqueryable
will fix your problem.
Source: stackoverflow.com
Related Query
- different search result by changing var to IEnumerable
- Can I use a LINQ IEnumerable result as the data source for a Gtk.TreeView?
- How to assign two different entities result set into single var variable using linq to sql c#
- How to assign the same var type variable to different linq to sql result sets?
- Entity Framework, Code First and Full Text Search
- Is there an IEnumerable implementation that only iterates over it's source (e.g. LINQ) once?
- Serializing result of a LINQ IEnumerable
- In which cases do I need to create two different extension methods for IEnumerable and IQueryable?
- IQueryable<T> gives different result than a List<T>
- using Comparer to sort IEnumerable in C# by different fields
- Is it possible to perform a LINQ aggregate over a collection of one type to a different result type?
- How to intersect two different IEnumerable collections
- Linq search result by closest match
- LINQ Source Code Available
- c# Convert LINQ var result to actual type
- Why do these three pieces of LINQ code produce different (or erroneous) results?
- .NET 4 Code Contracts: "requires unproven: source != null"
- LINQ query return same result despite different datasources
- Changing a piece of code into expressions
- Can Linq `Where` clause query result be different depending on whether query is executed lazily or non-lazily?
- Retrieve bool result by using LinQ code
- Search between Two IEnumerable - LINQ
- entity framework returning different result when predicate is passed
- Linq (or SQL): Get a search query and sort it order by best result
- creating Linq to sqlite dbml from DbLinq source code
- c# Different Result between Linq and SQL
- Running different code depending on what Net Framework version is installed
- How can i copy data table records of different field name based on mapping list evaluating condition on source data table?
- C# Linq GroupBy ==> Class vs Anonymous class --- different result
- Var vs IEnumerable when it comes to Entity Framework
More Query from same tag
- LINQ syntax for left join with last added value on the right
- Querying a many-to-many table by grouping
- How to make lambda do one db call instead of severals
- If and else with LINQ
- Conditional OrderBy
- How to get a note node having particular hashtag value
- Find node when traversing tree
- C# string manipulation problem
- Why I should not always be using ICollection instead of IEnumerable?
- Check availability in the List<T>
- System.IO - Use Directory/LINQ to Replace Some Files in a List with Others
- Test for all possibilities in a string
- Why does IEnumerable.Any return True for a collection of False-booleans?
- Contains method for compare string array in C#
- How do I optimize checking for any added, deleted or updated items on a list with Linq to Objects?
- How can I write to an Excel spreadsheet using Linq?
- How two compare two array list items in linq query vb.net
- how to Order a CollectionA using ListB ordering it in order of ListB Items in VB.net
- Can I use LINQ to compare what is missing, added or updated between two collections
- LINQ distinct on class item?
- How to get sublist from left outter join table using linq query?
- How to create MongoDB MultiKey index on attribute of items in an array .NET Driver
- LINQ to SQL to query parent and count childs in hierarchy
- How to embed dynamic OR condition after WHERE statement in linq query c#
- Passing a collection of item to search for in LINQ
- skip entire row if particular cell value contains zero in datatable C#
- Linq RemoveAll for a predicate condition on a list inside the collection
- Speed of linq query grouping and intersect in particular
- Converting each and every attribute of xml into datatable column and filling its inner text as column value
- Updating a complex object with linq and Entity Framework