-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StackOverflowException with EFCore 5 many-to-many mapping using many-to-one via self #23377
Comments
@AndriySvyryd Thoughts? |
Just want to point out that
This line is configuring M2M between Employee and Region using Employee as join entity. The 2nd FK in UsingEntity is also self-ref. |
It's indeed a self-referencing m:n with itself as the intermediate, as there are two m:1 relationships with the same entity as the 'm' side. It's a bit of an edge case perhaps although self-referencing relationships are sometimes used for m:n relationships... |
This isn't something that we support in 5.0, but we should fix the SOE |
Ok, I'll make a validation rule to weed out this situation for now :) |
'This' means: a m:n based on a relationship with self or a m:n with self or both? |
Note from triage: we will bring this to Tactics to patch for a better exception than the stack overflow. |
EF Core version: 5.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0
Operating system: Windows 10
IDE: (e.g. Visual Studio 2019 16.8)
Stacktrace:
long stackoverflow stacktrace
Stack overflow.
at System.Globalization.CompareInfo.IcuCompareString(System.ReadOnlySpan
1<Char>, System.ReadOnlySpan
1, System.Globalization.CompareOptions)at System.Globalization.CompareInfo.Compare(System.ReadOnlySpan
1<Char>, System.ReadOnlySpan
1, System.Globalization.CompareOptions)at System.Globalization.CompareInfo.Compare(System.String, System.String, System.Globalization.CompareOptions)
at System.String.Compare(System.String, System.String, System.StringComparison)
at System.String.CompareTo(System.String)
at System.Collections.Generic.GenericComparer
1[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Compare(System.__Canon, System.__Canon) at System.Collections.Generic.SortedDictionary
2+KeyValuePairComparer[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].Compare(System.Collections.Generic.KeyValuePair2<System.__Canon,System.__Canon>, System.Collections.Generic.KeyValuePair
2<System.__Canon,System.__Canon>)at System.Collections.Generic.SortedSet
1[[System.Collections.Generic.KeyValuePair
2[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].FindNode(System.Collections.Generic.KeyValuePair2<System.__Canon,System.__Canon>) at System.Collections.Generic.SortedDictionary
2[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].TryGetValue(System.__Canon, System.__Canon ByRef)at Microsoft.EntityFrameworkCore.Infrastructure.Annotatable.FindAnnotation(System.String)
at Microsoft.EntityFrameworkCore.Infrastructure.Annotatable.get_Item(System.String)
at Microsoft.EntityFrameworkCore.RelationalModelExtensions.GetDefaultSchema(Microsoft.EntityFrameworkCore.Metadata.IModel)
at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions.GetDefaultSchema(Microsoft.EntityFrameworkCore.Metadata.IEntityType)
at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions.GetSchema(Microsoft.EntityFrameworkCore.Metadata.IEntityType)
at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions+<>c__DisplayClass6_0.b__4(Microsoft.EntityFrameworkCore.Metadata.ISkipNavigation)
at System.Linq.Enumerable.All[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable
1<System.__Canon>, System.Func
2<System.__Canon,Boolean>)at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions.GetDefaultSchema(Microsoft.EntityFrameworkCore.Metadata.IEntityType)
at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions.GetSchema(Microsoft.EntityFrameworkCore.Metadata.IEntityType)
at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions+<>c__DisplayClass6_0.b__4(Microsoft.EntityFrameworkCore.Metadata.ISkipNavigation)
at System.Linq.Enumerable.All[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable
1<System.__Canon>, System.Func
2<System.__Canon,Boolean>)at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions.GetDefaultSchema(Microsoft.EntityFrameworkCore.Metadata.IEntityType)
at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions.GetSchema(Microsoft.EntityFrameworkCore.Metadata.IEntityType)
at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions+<>c__DisplayClass6_0.b__4(Microsoft.EntityFrameworkCore.Metadata.ISkipNavigation)
at System.Linq.Enumerable.All[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable
1<System.__Canon>, System.Func
2<System.__Canon,Boolean>)at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions.GetDefaultSchema(Microsoft.EntityFrameworkCore.Metadata.IEntityType)
at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions.GetSchema(Microsoft.EntityFrameworkCore.Metadata.IEntityType)
at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions+<>c__DisplayClass6_0.b__4(Microsoft.EntityFrameworkCore.Metadata.ISkipNavigation)
at System.Linq.Enumerable.All[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable
1<System.__Canon>, System.Func
2<System.__Canon,Boolean>)at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions.GetDefaultSchema(Microsoft.EntityFrameworkCore.Metadata.IEntityType)
at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions.GetSchema(Microsoft.EntityFrameworkCore.Metadata.IEntityType)
at Microsoft.EntityFrameworkCore.RelationalEntityTypeExtensions+<>c__DisplayClass6_0.b__4(Microsoft.EntityFrameworkCore.Metadata.ISkipNavigation)
at System.Linq.Enumerable.All[[System.__Canon, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.Collections.Generic.IEnumerable
1<System.__Canon>, System.Func
2<System.__Canon,Boolean>)at
...
etc.
Attached you'll find a repro case. The culprit is this relationship:
this one:
It has a m:n relationship via a relationship with itself. Commenting this m:n relationship mapping fixes it.
It might be I made a mapping mistake, but I don't see how I can map it otherwise.
Repro:
EF5CoreStackOverflowWithMNViaSelf.zip
The text was updated successfully, but these errors were encountered: