Hi,
I am developing an api in asp.net webapi core 6.
Following is my datacontext. My class seems to be 100% compatible as I see in the Microsoft/MSDN documentations but why I am getting the warnings in Visual Studio 2022 ?
(https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro?view=aspnetcore-6.0)
public class CarRentalContext : DbContext
{
public CarRentalContext(DbContextOptions<CarRentalContext> options)
: base(options)
{
}
public DbSet<FranchiseWebInquiry> FranchiseWebInquiries { get; set; }
public virtual DbSet<Franchise> Franchises { get; set; }
public virtual DbSet<Franchise_BankHolidays> Franchise_BankHolidays { get; set; }
public virtual DbSet<Franchise_OpeningHours> FranchiseOpeningHours { get; set; }
public virtual DbSet<Enquiry> Enquiries { get; set; }
public virtual DbSet<Fleet> Fleets { get; set; }
public virtual DbSet<Tariff> Tariffs { get; set; }
public virtual DbSet<BookingAgreement> BookingAgreements { get; set; }
}
See my warning messages.
Why I would have to create a property as nullable in datacontent while using EF CORE 6.
Severity Code Description Project File Line Suppression State
Warning CS8618 Non-nullable property 'FranchiseWebInquiries' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. CarRental D:\Git Source Code\Temp\Release1\temp_1\CarRental\DB\CarRentalContext.cs 14 Active
Warning CS8618 Non-nullable property 'Franchises' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. CarRental D:\Git Source Code\temp\Release1\temp_1\CarRental\DB\CarRentalContext.cs 14 Active
Warning CS8618 Non-nullable property 'Franchise_BankHolidays' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. CarRental D:\Git Source Code\temp\Release1\temp_1\CarRental\DB\CarRentalContext.cs 14 Active
Warning CS8618 Non-nullable property 'FranchiseOpeningHours' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. CarRental D:\Git Source Code\temp\Release1\temp_1\CarRental\DB\CarRentalContext.cs 14 Active
Warning CS8618 Non-nullable property 'Enquiries' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. CarRental D:\Git Source Code\temp\Release1\temp_1\CarRental\DB\CarRentalContext.cs 14 Active
Warning CS8618 Non-nullable property 'Fleets' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. CarRental D:\Git Source Code\temp\Release1\temp_1\CarRental\DB\CarRentalContext.cs 14 Active
Warning CS8618 Non-nullable property 'Tariffs' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. CarRental D:\Git Source Code\temp\Release1\temp_1\CarRental\DB\CarRentalContext.cs 14 Active
Warning CS8618 Non-nullable property 'BookingAgreements' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. CarRental D:\Git Source Code\temp\Release1\temp_1\CarRental\DB\CarRentalContext.cs 14 Active