skip to Main Content

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

3

Answers


  1. 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.

    Login or Signup to reply.
  2. 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>
    
    Login or Signup to reply.
  3. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search