Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Must contain a non-null value and possible null reference

I’m trying to switch to .Net 6.0 from .Net 3.1 and I encounter a few issues.

Apparently, in .Net 6.0 models need to have non-nullable property, for example:

public string Email { get; set; } = String.Empty;

The problem for the DbSet I fixed like:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public DbSet<User>? Users { get; set; }

However, now I’m getting warnings of possible null reference argument/return as the image below:

possiblenull

>Solution :

As the docs show you can use Set method with expression bodied property:

public DbSet<User> Users => Set<User>();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading