Skip to content
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

Add test for...ThenInclude value cannot be null #16107

Closed
kccsf opened this issue Jun 15, 2019 · 6 comments · Fixed by #17972
Closed

Add test for...ThenInclude value cannot be null #16107

kccsf opened this issue Jun 15, 2019 · 6 comments · Fixed by #17972
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@kccsf
Copy link

kccsf commented Jun 15, 2019

var test = await dbcontext.SomeEntity
.Include(x => x.SecondEntity).ThenInclude(x => x.ThirdEntity)
.SingleOrDefaultAsync(x => x.Id == id);

Fails when SecondEntity is null.

Works when ThenInclude is removed. Also works if SecondEntity is not null even if ThirdEntity is null.

Exception message:
Value cannot be null.\r\nParameter name: key

Stack trace:
"   at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)\r\n   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)\r\n   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityReferenceMap.TryGet(Object entity, IEntityType entityType, InternalEntityEntry& entry, Boolean throwOnNonUniqueness)\r\n   at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.TryGetEntry(Object entity, Boolean throwOnNonUniqueness)\r\n   at Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.RelationalShapedQueryCompilingExpressionVisitor.IncludeCompilingExpressionVisitor.IncludeReference[TEntity,TIncludedEntity](QueryContext queryContext, DbDataReader dbDataReader, TEntity entity, Func`4 innerShaper, INavigation navigation, INavigation inverseNavigation, Action`2 fixup, Boolean trackingQuery, ResultCoordinator resultCoordinator)\r\n   at Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.RelationalShapedQueryCompilingExpressionVisitor.IncludeCompilingExpressionVisitor.IncludeCollection[TEntity,TIncludedEntity](QueryContext queryContext, DbDataReader dbDataReader, TEntity entity, Func`3 outerKeySelector, Func`3 innerKeySelector, Func`4 innerShaper, INavigation navigation, INavigation inverseNavigation, Action`2 fixup, Boolean trackingQuery, ResultCoordinator resultCoordinator)\r\n   at Microsoft.EntityFrameworkCore.Relational.Query.Pipeline.RelationalShapedQueryCompilingExpressionVisitor.AsyncQueryingEnumerable`1.AsyncEnumerator.<MoveNextAsync>d__17.MoveNext()\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()\r\n   at Microsoft.EntityFrameworkCore.Query.Pipeline.ShapedQueryCompilingExpressionVisitor.<SingleOrDefaultAsync>d__12`1.MoveNext()\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at Microsoft.EntityFrameworkCore.Query.Pipeline.ShapedQueryCompilingExpressionVisitor.<SingleOrDefaultAsync>d__12`1.MoveNext()\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at Web.Controllers.DataController.<GetItem>d__8.MoveNext() in xxxxxxxxxxx.cs:line 165"

Steps to reproduce

Have private repo if required

Further technical details

EF Core version: 3.0.0-preview7.19314.2
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2019 16.2.0 Preview 2

@smitpatel
Copy link
Contributor

@kccsf - Thanks for reporting. I believe I know where the bug is. Repro is not necessary. :)

@kccsf
Copy link
Author

kccsf commented Jun 15, 2019

No problem; thanks again for such speedy feedback! :-)

@ajcvickers ajcvickers added this to the 3.0.0 milestone Jun 17, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, 3.0.0-preview7 Jul 2, 2019
@ajcvickers ajcvickers self-assigned this Jul 24, 2019
@ajcvickers
Copy link
Contributor

@smitpatel to write a note on how to fix this.

@smitpatel smitpatel added the verify-fixed This issue is likely fixed in new query pipeline. label Jul 24, 2019
@smitpatel
Copy link
Contributor

Code change in #16212 should fix this.

@kccsf
Copy link
Author

kccsf commented Jul 24, 2019

Thanks - working in 3.0.0-preview7.19365.7

@kccsf kccsf closed this as completed Jul 24, 2019
@smitpatel smitpatel reopened this Jul 24, 2019
@smitpatel
Copy link
Contributor

@kccsf - Thanks for verifying.
@ajcvickers - Should this moved to backlog to add regression test?

@ajcvickers ajcvickers changed the title ThenInclude value cannot be null Add test for...ThenInclude value cannot be null Jul 24, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, Backlog Jul 24, 2019
@smitpatel smitpatel removed the query label Sep 3, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 3.1.0 Sep 4, 2019
@smitpatel smitpatel self-assigned this Sep 12, 2019
smitpatel added a commit that referenced this issue Sep 20, 2019
@smitpatel smitpatel added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed verify-fixed This issue is likely fixed in new query pipeline. labels Sep 20, 2019
@smitpatel smitpatel modified the milestones: 3.1.0, 3.0.0 Sep 20, 2019
smitpatel added a commit that referenced this issue Sep 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants