How to solve this ASP.NET MVC data null constructor warning on DbContext?
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
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>
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.