In my server, my field "Name" is marked as [Required] so EntityFramework can mark it as non nullable on the migration:
public class MyClass
{
[Required]
public string? CreatedBy {get;set;}
}
But the "CreatedBy" field is set at creation on the server, so the first time it must travel as NULL from the client
So I get a serialization error:
https://tools.ietf.org/html/rfc7231#section-6.5.1
[‘The CreatedBy field is required.’]
How do I declare the CreatedBy field to be null for serialization but non null for database?
2
Answers
Since I don't want to use fluent api for this, I decided to disable the serialization validation:
program.cs
Remove the
Required-Attribute
and set theCreatedBy
field as required inOnModelCreating()
: