C
C#2y ago
Anton

❔ EF Core nullability vs API nullability behavior

In EF Core, nullability of properties is deduced from the nullability of their type. In API's however, even if the type of property is not nullable, it's deduced to be optional unless I apply [Required]. Also, EF Core ignores public getters without setters, while API's serialize them. I'm judging by the generated swagger schema. Is there a way to configure them to behave the same way, at least for nullability?
3 Replies
Angius
Angius2y ago
You shouldn't be exposing your EF classes via the API anyway
Anton
Anton2y ago
yeah I've made dtos for everything. but the nullability thing still applies. I have to put [Required] even on non nullable things
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.