本文介绍了N-Tier Web-App - 乐观并发与last-update-wins ...需要时间戳吗? RowVersion?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 如果这个问题已经回答,我首先道歉,但我的搜索空手而归。 (或者我真的很蠢) 我有一个网络应用程序(MVC.Net),这是我们的工作流程: on HttpGet - 使用新的DataContext从数据库中检索对象 显示给用户进行编辑 在HttpPost上 - 从数据库重新检索对象(同样,使用新的DataContext) 使用模型绑定更新最近检索的对象 保存到数据库(即使用与步骤3中相同的DataContext的submitchanges) 注意:我们的Action Controllers在每个方法中使用一个新的DataContext,因此不需要像DataContext.Refresh或"Attach"那样做。实体。我对Attach的理解实际上是针对序列化对象的,这不是这里的情况。 所以,我的问题是 - 你如何处理乐观并发?即澄清: 用户A检索对象 用户B检索对象 用户B重新检索对象,更新,保存到数据库 用户A重新检索对象,更新,保存到数据库 - 最后一场胜利!不是我想要的。 我假设必须有某种时间戳,rowversion,对吧?然后,你如何让LINQ提出异常?或者,我们是否应该在重新检索阶段自行检查? 谢谢!解决方案 My apologies first if this question already answered, but my searches came up empty-handed. (or I'm just really stupid)I have a web app (MVC.Net) and here is our workflow:on HttpGet - retrieve object from database using new DataContext display to user for editing on HttpPost - re-retrieve object from database (again, using new DataContext)use model binding to update recently retrieved object save to database (i.e. use submitchanges from same DataContext as in step 3) Notes: Our Action Controllers uses a new DataContext in each method, so no need to do things like DataContext.Refresh or "Attach" Entities. My understanding of Attach is really for serialized objects, and that is not the case here.So, my question is -- how do you handle optimistic concurrency? i.e. to clarify:user A retrieves object user B retrieves object user B re-retrieves object, updates, saves to db user A re-retrieves object, updates, saves to db -- last one wins! not what I want.I'm assuming there must be some kind of timestamp, rowversion, right? And then, how do you get LINQ to raise an exception? Or, should we check it ourselves during the re-retrieve phase?Thanks! 解决方案 这篇关于N-Tier Web-App - 乐观并发与last-update-wins ...需要时间戳吗? RowVersion?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-28 01:43