How to avoid Null Insert on Required TPH Columns for types that don't implement the required column

233 Views Asked by At

I've get a set of Class that utilize TPH inheritance.

So all of the types are in the "Documents" table.

Some document types have unique fields. If a sub document type has a non nullable field, the other types are getting an error when creating the entity, because EF tries to insert NULL into that column in the DB - because the subtype doesn't know about that column.

I have tried using defaultValue in a migration to default it to zero, but get the same result.

Is it possible to have a non nullable field in an inherited type, where the base type does not have that field at all?

Or will that always result in the "cannot insert the value Null in column x" error?

In this case the column is an enum.

Should I make it nullable and force it to be required some other way?

0

There are 0 best solutions below