This question is related to EF Core Issue #13079: Columns for nested owned types don't allow NULL although owned by derived entity. But it may be of interest more generally (e.g. if an existing not-well-modeled database has to be matched). At least for nested owned types within derived entities with TPH it would provide a way to configure the database such that its schema by now is like it will be after the linked issue is fixed:
Can a database column for a property be configured to allow NULL
even if the property type is not nullable? If yes, how?
Given the following type:
public class SubData
{
public Int32 Prop { get; set; }
}
Is it possible to manually configure the database column for SubData.Prop
to allow NULL
?
IsRequired(false)
cannot be used because Int32
is not nullable. If needed we may assume that the name of the column is known to be, say, Data_SubData_Prop
, and that the name of the table is, say, Entity
. Probably it could be done using SQL ALTER COLUMN
. But can it be done by Fluent API, too?