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?
- why does this linq code get exponentially slower when applying First() to projection?
- Why this LINQ throws NullReferenceException?
- Convert this LINQ code back to a Loop (or Why is this object sometimes null)
- 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?
- Why this multi linq join code does not work?
- Why does the C# compiler go mad on this nested LINQ query?
- Why does this Linq Cast Fail when using ToList?
- Why does adding an unnecessary ToList() drastically speed this LINQ query up?
- LINQ query to perform a projection, skipping or wrapping exceptions where source throws on IEnumerable.GetNext()
- Why is LINQ faster in this example
- why is this linq query return a boolean and not the first result of the select?
- Why am I required to reference System.Numerics with this simple LINQ expression?
- Why does EF 5.0 not support this EF 4.x LINQ syntax when compiling to sql?
- Enumerable.Empty<T>().AsQueryable(); This method supports the LINQ to Entities infrastructure and is not intended to be used directly from your code
- Why won't this LINQ join statement work?
- Why is this LINQ query not executed when using foreach?
- Does this LINQ code perform multiple lookups on the original data?
- Why doesn't this code compile in VS2010 with .NET 4.0?
- why .ToList().Distinct() throws error but not the .Distinct().ToList() with linq query
- Why does this LINQ grouping have a count of 3 instead of 2?
- Why is this code with PredicateBuilder not working?
- Why isn't this LINQ Group By aggregating the rows in vb.net?
- LINQ Source Code Available
- Why does this LINQ query compile?
- How does this linq code that splits a sequence work?
- multiple orderby in this linq code
- Why is this linq expression not working?
- Why doesn't using a nullable Guid work in this linq query?
- How can I combine this code into one or two LINQ queries?
More Query from same tag
- Populating a XAML Store App combobox from a Linq Query
- Workaround for "LINQ to Entities does not recognize the method 'Int32 Parse(System.String)'
- Entity Framework - null reference within many-to-many table
- Build LINQ Select conditionally similar of using PredicateBuilder for Where clause
- Verify type, properties of Linq object with T anonymous parameter in function
- Assign a list of strings to a propertis - filtering periods and displaying the number of orders in a given period
- Linq - sum child field value when child records query ganareted by diffrent func
- How can I merge time entries into a single row for a weekly report?
- Why is my DTO Null?
- Getting the error "cannot add an entity that already exists." while inserting a table's value in to DB without procedure
- LINQ to SQL how to use it in .ashx file to generate json?
- dynamically building a Mongo Query using C# and the fluent library
- Convert simple t-sql query to linq
- Even easiest join gets complicated in NHibernate
- Linq To XML problems and databinding
- Chaining multiple Linq Where calls as an OR, not an AND
- How to get DbSet<SomeClass> (EF) from the dbContext using reflection?
- XML invalid Character !.
- Using variables to build a LinQ query?
- Joining 2 lists with condition
- ListView with ODS, BusinessLayer and Dynamic Linq doesn't sort
- C# Interface IEnumerable Any() without specifying generic types
- Best way to emulate the functionality of Python's "in" keyword in C#?
- Inconsistencies with Groupby in .Net-Framework
- "Grouping" dictionary by value
- RavenDB query with Linq and enum
- LINQ query with many tables, left outer joins, and where clause
- Linq VAR and Typed Object
- Checking for null in a collection
- SortedDictionary in reverse order of keys