Entity Framework 6 w/ DatabaseGeneratedOption.Computed: column does not allow nulls. INSERT fails

c# calculated-columns entity-framework entity-framework-6 sql-server

Accepted Answer

It turns out that EF was set up to utilise Automatic Migrations rather than our own migrations while performing integration tests. As a result of the calculated columns being inserted in a unique SQL script across theUp the columns weren't really used as a migration techniquecomputed columns throughout the testing, but they were really produced by EF as ordinarydecimal fields that cannot be null. Therefore, when attempting to add a new model to the context, EF was insertingNULL bursting into the columns.

The migrations should really be executed in the integration tests as a solution. After the column has been calculated, EF stops keeping track of it.

1
7/10/2017 6:48:19 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow