Is it possible to have Entity framework generate a table, from a model, with the column marked as not null without using the [Required]
annotation on the model's property?
Reason:
The object is posted to an api and I check ModelState.IsValid
in the controller. The property is supposed to be generated server side and not come from outside, but if I have the property [Required]
the ModelState.IsValid
is false (in which case I return with a BadRequest(ModelState);
).
Can I tell EF to make the column not null in some other way?
I guess another solution would be to expect another object(some sort of DTO) to be sent to the api and then do a mapping. But that object would look exactly the same save for this single property, which makes it seem a bit unnecessary, right?