Why does EF Seed Method Insert Null on DateTime?

c# entity-framework entity-framework-6

Accepted Answer

I'm good, folks.

I solve the issue (kinda).

Ivan Stoev deserves credit for bringing up the calculated and identity qualities.

In my DbContext, I did have the following line:

modelBuilder.Properties<DateTime>().Where(x => x.Name == "AdmCreatedDate")
.Configure(c => c.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed));

For some reason, when the Seed method attempts to execute when the object contains a calculated attribute, EF does not like it. I spoke to the project manager and persuaded her to remove the computation from EF since it has no impact whatsoever on the database. EF solely manages it at the code level. I discovered the column is not really set as calculated after inspecting the database in SQL Server.) Sincerely, I don't like this since the calculated properties will be lost if we decide later not to utilise EF.

In conclusion, the Seed() function cannot include models with calculated attributes.

The calculated column is now handled in the real database.

Why EF acts in this manner is something that would be wonderful to know but that I was unable to discover online. Please let me know if you know if anybody does.

Hope this is useful:)

0
7/27/2018 8:55:29 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