3

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?

Carlos Blanco
  • 8,592
  • 17
  • 71
  • 101
  • is it a computed column or it has got a default value? how do you calculate the date in that column? – johnny Dec 13 '13 at 17:33
  • default value from the DB – Carlos Blanco Dec 13 '13 at 18:07
  • You could use an alternative to the data annotation. This answer may help: http://stackoverflow.com/questions/584556/how-to-use-default-column-value-from-database-in-entity-framework – Mike Dec 13 '13 at 18:26

1 Answers1

5

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.

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291