0

I have a rowversion (timestamp) column which is set to computed in my EF designer.

Setting the value in code, via the direct property like

     myEnt.rowversion = screenRowVersion;

has now effect when SaveChanges() is called, a trace to SQLServer shows that the original value of rowversion is used.

Is it possible to have the DbContext API accept an external computed value?

leppie
  • 115,091
  • 17
  • 196
  • 297
Scott Weinstein
  • 18,890
  • 14
  • 78
  • 115

1 Answers1

1

EF doesn't allow overriding computed values - it always uses original values loaded from the database. There is workaround for this where you cheat EF and change the original value tracked by the context:

context.Entry(myEnt).OriginalValues["rowversion"] = screenRowVersion;

But anyway in case of timestamp it is not needed. You have the old timestamp and a new timestamp so you can compare them in your application without necessary roundtrip to database.

Community
  • 1
  • 1
Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670