OptimisticConcurrencyException Does Not Work in Entity Framework In Certain Situations

前端 未结 4 1437
小鲜肉
小鲜肉 2020-12-24 02:59

UPDATE (2010-12-21): Completely rewrote this question based on tests that I\'ve been doing. Also, this used to be a POCO specific question, but it turns out that my

4条回答
  •  一向
    一向 (楼主)
    2020-12-24 03:13

    If it's EF Code first, then use code similar to below code. This will change the original TimeStamp loaded from db to the one from UI and will ensure OptimisticConcurrencyEception occurs.

    db.Entry(request).OriginalValues["Timestamp"] = TimeStamp;
    

提交回复
热议问题