score:3

Accepted answer

That was really a bug, and was corrected in LINQ 4.0

http://damieng.com/blog/2009/06/01/linq-to-sql-changes-in-net-40

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.

score:0

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.

score:0

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


Related Articles