3

Screenshot of My Code

The following code is from the official MS documentation; I followed as same for to solve this warning issues.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using MvcMovie.Models;

namespace MvcMovie.Data
{
    public class MvcMovieContext : DbContext
    {
        public MvcMovieContext (DbContextOptions<MvcMovieContext> options)
            : base(options)
        {
        }

        public DbSet<MvcMovie.Models.Movie> Movie { get; set; }
    }
}

official MS Documents

2
  • 2
    Everything in documentation Commented Jan 11, 2022 at 7:36
  • Make it Nullable using ?. Commented Jan 11, 2022 at 12:28

3 Answers 3

3

in the document link you posted , you should have founnd this warning

"To eliminate the warnings from nullable reference types, REMOVE the following line from the MvcMovie.csproj file "

<Nullable>enable</Nullable>
Sign up to request clarification or add additional context in comments.

Comments

2

In you MvcMovieContext class, instread that :

public DbSet<MvcMovie.Models.Movie> Movie { get; set; }

Simply do that :

public DbSet<MvcMovie.Models.Movie>? Movie { get; set; }

And it's done. Otherwise tell me if it doesn't work.

3 Comments

Thank You its Working fine now without any warring
No problem. Don't forget to click on the upper arrow on the answer for validate it.
But this will cause a null warning everywhere else that I use 'Movie'.
0

The best way remove this line in .csproj => Nullable enable Nullable If you do like this :

public DbSet<MvcMovie.Models.Movie>? Movie { get; set; }

It will Warning in other files

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.