Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Computed column in entity framework

I have a DateTime column in my app that gets auto calculated by SQLServer. It works great when creating the row. However, I would like to be able to updated later. I have the property marked with [DatabaseGenerated(DatabaseGeneratedOption.Computed)].

Is it possible to updated a property like that in EF?

like image 231
Carlos Blanco Avatar asked Aug 12 '26 04:08

Carlos Blanco


1 Answers

No, with DatabaseGeneratedOption.Computed EF will never include the property in update and insert statements. In stead, it will always read its value after such statements.

If you have to update the property in client code you have no other option than removing the data annotation an make it an ordinary updateable property. You can set a default value in the owning class's constructor.

like image 136
Gert Arnold Avatar answered Aug 14 '26 18:08

Gert Arnold