That was really a bug, and was corrected in LINQ 4.0
Query stability Contains now detects self-referencing IQueryable and doesn't cause a stack overflow
EDIT In .NET 3.5 to resolve the problem: When using 'Auto Generated Value' = True, then you must set 'Delay Loaded' to False - otherwise you get the recursion error.
EDIT2 The solution above didn't work.
Put a breakpoint on the last line, then run the code. Then when it stops on the breakpoint, add another breakpoint at the start of that chunk of code. Then continue in the debugger (step over). It should hit the new breakpoint, and you can examine the stack to see how it has called back on itself.
What's the implementation of the
Operation property? Maybe that calls back into some other code in a recursive way.
I know this is an old post already, but changing the Contains method to Equals worked for me also.
This fails with StackOverflowException
Dim iLottery As IEnumerable(Of Lottery) = From lottery2 In combined2 Where Not (From lottery1 In combined Select lottery1.NUMBER).Contains(lottery2.NUMBER) Select lottery2
This does not
Dim iLottery As IEnumerable(Of Lottery) = From lottery2 In combined2 Where Not (From lottery1 In combined Select lottery1.NUMBER).Equals(lottery2.NUMBER) Select lottery2
- Why this Linq code always throws System.StackOverflowException?
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Does this LINQ code perform multiple lookups on the original data?
- LINQ Source Code Available
- How does this linq code that splits a sequence work?
- multiple orderby in this linq code
- How can I combine this code into one or two LINQ queries?
- How can I further simplify this piece of LINQ code
- Is there a bug in this code from 101 LINQ Samples on MSDN? (Update: Fixed)
- LINQ approach to this code
- .Cast<T> extension method always throws InvalidCastException - How are you supposed to use this method?
- creating Linq to sqlite dbml from DbLinq source code
- How do i convert this linq code to inline sql
- why does this linq code get exponentially slower when applying First() to projection?
- How to convert this recursive code to Linq
- Why this LINQ throws NullReferenceException?
- Using Linq to build a graph class; can you make this code look better?
- How to write this code using the Linq Extension Method-Syntax?
- Convert this LINQ code back to a Loop (or Why is this object sometimes null)
- How can I refactor this code for LINQ filtering?
- My code is very inefficient for this simple Linq usage
- How I change this code to be in linq style
- Why the extension method of where for LINQ in this code would print out a single number while it shouldn't print anything at all?
- Linq - how to convert this code to linq
- How best to optimise this small bit of c# Linq code
- how to write LINQ to objects equivalent code for this code
- Reduce the line of code for this LINQ query
- Can I can convert this C# code into some Linq code?
- Need to debug LINQ simple queries in Visual Studio 2010
- How to update one to many relationship using linq
- Dynamic Linq creation
- is there anyway to remove from a collection based on a .Where() linq clause (.RemoveWhere() ?)
- How to enable $expand and $select on ODataQueryOptions?
- Does LINQ "Query Syntax" Support Duck Typing?
- linq left outer join object reference not set to an instance of an object
- "Where" clause after "ProjectTo" and Nullable types?
- Clone (deep copy) Entity LINQ
- How to get ToDictionary to work in F#?
- self referential join using linq
- C# Linq query not returning an Enumerable collection
- Cast to a type inside a LINQ To Entity Query
- Linq to SQL over zealous serialization
- problem with filtering data from 2 tables in sql?
- How would I write this dynamic linq query?
- How to extract data from dictionary by LINQ
- LINQ to SQL, Stored Procedures and the Methods Pane (more like Methods PAIN!)
- Using a LINQ Where query to get only some of the ConfigurationManager.ConnectionStrings
- xml linq retrieving elements in same node