Works incompelete Fluent API in migration

79 views Asked by At

I created a model called ProductCategory (image #1) and configured this class using the Fluent API method (image #2), but unfortunately when I create Migration, all the configurations including the main key, the length of the allowed character string are applied, but The IsRequired feature is applied to all fields, but I specified only a few mandatory fields!!!!!!! Picture1(model)

Picture2(Fluent API)

Picture3 (Migration)

Thanks...

Even manually, I corrected the values in the migration and it was created correctly in the database, but when the user completes the form, the Field is required error is displayed for all fields.... also I update my visual studio to 17.5.3 and change dotnet version to 7 but the problem not solved.

1

There are 1 answers

1
Brando Zhang On BEST ANSWER

After C# 8.0 the Nullable Reference Types for all code in a project, that means all your property will be regard as the not-null property by default.

If you want your property not regard the not-null by default, you could remove your csproj file's <Nullable>enable</Nullable>.

enter image description here

Then it will create as not required.

Result:

enter image description here