VS 2022 ASP.NET Core MVC <Nullable>enable</Nullable> in projectName.csproj causes ModelState.IsValid = false CS8618 Non-nullable property

Viewed 413

I have 2 foreign key fields in a table, after updating to VS2022 my model can not post unless I do option 1 or 2.

  1. Allow the 2 foreign table fields in the many table to be null with the question mark as below:
public virtual DGroup? DGroup { get; set; }
public virtual ApplicationUser? ApplicationUser { get; set; }
  1. In the .csproj switch <Nullable>enable</Nullable> to <Nullable>disable</Nullable>

The 2 virtuals show up in ModelState, if I mark them null doesn't it affect my referential integrity? I want the database to cascade delete my 'many resolution' table on delete of my master table.

0 Answers
Related