question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Should EntityEntry's Expression-based parameters be nullable-friendly?

See original GitHub issue

Hi guys,

With EF Core 6.0 adopting nullable annotations pretty much everywhere, we now have a great coverage (thanks for that!). I’m currently testing my OpenIddict framework on the latest .NET 6.0 preview and I’m now seeing a few warnings caused by things like Context.Entry(authorization).Reference(entry => entry.Application) when the referenced navigation property is nullable, which requires using a null-forgiving operator to fix them (e.g Context.Entry(authorization).Reference(entry => entry.Application!)).

My question/demand is simple: is it the expected behavior or will the methods taking an expression accessor be updated at some point to allow referencing nullable navigation properties without triggering warnings?

/cc @roji as I believe you’ve taken care of most of the “add nullable annotations everywhere” tasks 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Apr 15, 2021

There’s also the possibility of constraining TProperty to class? instead of class, but that would flow through to the ReferenceEntry’s generic type as well, so we’d need to look a bit wider at how it all works together…

1reaction
rojicommented, Apr 15, 2021

@kevinchalet thanks for raising this - it seems to be a case of incorrect annotation.

Null-annotating the entire EF Core codebase is a massive task, and we’re bound to have made some mistakes - so I wouldn’t assume that any weirdness you’re seeing is by-design. Please don’t hesitate to flag such issues to us as you’ve done here.

@smitpatel I think you did most of change tracking, are you interested in taking a look? If not let me know.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Nullable comparisons in expression trees
Expression.Equal requires both parameters to be of the same type. If one is nullable, they both need to be nullable.
Read more >
Working with nullable reference types - EF Core
Collection navigations, which contain references to multiple related entities, should always be non-nullable. An empty collection means that no ...
Read more >
C# 11.0 preview: parameter null checking
In this post I'm going to describe what this new language feature does, and how it relates to and is distinct from nullable...
Read more >
Improve interop to Nullable optional parameters #774
I propose we improve interop to C#-defined Nullable-typed optional ... the known type will be relevant to checking the argument expression.
Read more >
SSRS report with Multi Value and Null Parameter
I am creating a report and i am adding a drop down menu with a multi value parameter. I want this multivalue parameter...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found