I'm trying to implement optimistic concurrency checking. I make use of the generic repository and unit of work patterns.
I have introduced a Timestamp-attributed property (as byte array) to my entity, which increases the value automatically whenever I update data (seems to be database managed, which is what it should do).
I load the updated values from a view model by mapping the VM to the actual model (using automapper). This results in a new (detached?) instance of an entity of the correct type with all the according fields set (including the timestamp).
The update itself is performed like
i_oOldEntity = m_oDbSet.Find(i_oEntity.MaterialId)
context.Entry(i_oOldEntity).CurrentValues.SetValues(i_oEntity)
context.SaveChanges()
with i_oEntity being the automapped entity.
This updates the values itself fine, however it completely ignores the timestamp-value coming from the viewmodel. The resulting SQL code uses the latest rowversion value in the WHERE clause.
In short: how do I get my viewmodel-timestamp values to be used in the WHERE clause from EF?