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

Return values of SingleOrDefaultAsync incorrect when nullable reference types are enabled #21793

Closed
dannyBies opened this issue Jul 26, 2020 · 5 comments

Comments

@dannyBies
Copy link

In my project I have nullable reference types enabled.
<Nullable>enable</Nullable>

I believe the return type is incorrect for the following methods in EntityFrameworkQueryableExtensions.cs

  • FirstOrDefaultAsync
  • LastOrDefaultAsync
  • SingleOrDefaultAsync

I believe those methods should use the [return: MaybeNull] attribute just like equivalent System.Linq methods do.

Steps to reproduce

image

I would expect a build error at foundInvite.Expired as this could return null.

Further technical details

EF Core version: 5.0.0-preview.7.20365.15
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET5
Operating system: Windows 10
IDE: 16.7.0 Preview 5.0

@roji
Copy link
Member

roji commented Jul 26, 2020

Simply adding [MaybeNull] isn't the right solution here for the async methods, see #21794 (comment).

@roji
Copy link
Member

roji commented Jul 26, 2020

Duplicate of #19007

@roji roji marked this as a duplicate of #19007 Jul 26, 2020
@roji
Copy link
Member

roji commented Jul 31, 2020

@dannyBies T? is being added for C# 9, which would be the correct annotation for this (as it allows annotating the nested generic type parameter): dotnet/roslyn#45993

@dannyBies
Copy link
Author

That's great, thanks for letting me know! Any idea when this will be usable in this project? I can make the necessary changes once T? is available here.

@roji
Copy link
Member

roji commented Jul 31, 2020

We're definitely not going to be doing any nullability annotation work for the upcoming 5.0 release (which is being stabilized), but I really hope we have time to that for 6.0. Track #19007 to know what's going on.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants