N-Tier Web-App - 乐观并发与last-update-wins ...需要时间戳吗? RowVersion? [英] N-Tier Web-App -- Optimistic concurrency vs last-update-wins... need timestamp? RowVersion?

查看:63
本文介绍了N-Tier Web-App - 乐观并发与last-update-wins ...需要时间戳吗? RowVersion?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果这个问题已经回答,我首先道歉,但我的搜索空手而归。 (或者我真的很蠢)


我有一个网络应用程序(MVC.Net),这是我们的工作流程:


  1. on HttpGet - 使用新的DataContext从数据库中检索对象
  2. 显示给用户进行编辑
  3. 在HttpPost上 - 从数据库重新检索对象(同样,使用新的DataContext)
  4. 使用模型绑定更新最近检索的对象
  5. 保存到数据库(即使用与步骤3中相同的DataContext的submitchanges)

注意:我们的Action Controllers在每个方法中使用一个新的DataContext,因此不需要像DataContext.Refresh或"Attach"那样做。实体。我对Attach的理解实际上是针对序列化对象的,这不是这里的情况。


所以,我的问题是 - 你如何处理乐观并发?即澄清:


  1. 用户A检索对象
  2.  用户B检索对象
  3.  用户B重新检索对象,更新,保存到数据库
  4.  用户A重新检索对象,更新,保存到数据库  - 最后一场胜利!不是我想要的。

我假设必须有某种时间戳,rowversion,对吧?然后,你如何让LINQ提出异常?或者,我们是否应该在重新检索阶段自行检查?


谢谢!

解决方案

Hello Bob,


 


欢迎来到LINQ到SQL论坛!


 


关于如何在LINQ to SQL中进行并发检查,我建议你参考这个博客,
h ttp://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/07/01/10557.aspx   


 


有关LINQ to SQL中的乐观并发和更改冲突的其他信息,请参阅
http://msdn.microsoft.com/en-us/library/bb399373.aspx   


 


如何:通过保留数据库值来解决并发冲突
(LINQ to SQL)


描述如何使用数据库值覆盖当前值。


如何:
解决并发问题通过覆盖数据库值(LINQ to SQL)发生冲突


描述如何通过覆盖数据库值来保持当前值。    
(最后一次胜利)


如何:解决并发问题
通过与数据库值合并冲突(LINQ to SQL)


描述如何通过合并数据库和当前值来解决冲突。


 


如果您有任何疑问,请随时告诉我。


 


美好的一天!


< span style ="font-family:Calibri"> 


 


<跨度style ="font-family:Calibri">最好的问候,

Lingzhi Sun


MSDN用户支持
在论坛


< span style ="font-size:12pt"> 如果您对我们的支持有任何反馈,请联系
msdnmg@microsoft.com


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:

  1. on HttpGet - retrieve object from database using new DataContext
  2. display to user for editing
  3. on HttpPost - re-retrieve object from database (again, using new DataContext)
  4. use model binding to update recently retrieved object
  5. 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:

  1. user A retrieves object
  2.  user B retrieves object
  3.  user B re-retrieves object, updates, saves to db
  4.  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!

解决方案

Hello Bob,

 

Welcome to LINQ to SQL forum!

 

About how to make the concurrency check in LINQ to SQL, I would recommend you refer to this blog, http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2008/07/01/10557.aspx.  

 

For additional information about the optimistic concurrency and change conflicts in LINQ to SQL, please see http://msdn.microsoft.com/en-us/library/bb399373.aspx.  

 

How to: Resolve Concurrency Conflicts by Retaining Database Values (LINQ to SQL)

Describes how to overwrite current values with database values.

How to: Resolve Concurrency Conflicts by Overwriting Database Values (LINQ to SQL)

Describes how to keep current values by overwriting database values.    (last-win)

How to: Resolve Concurrency Conflicts by Merging with Database Values (LINQ to SQL)

Describes how to resolve a conflict by merging database and current values.

 

If you have any questions, please feel free to let me know.

 

Good day!

 

 

Best Regards,
Lingzhi Sun

MSDN Subscriber Support in Forum

If you have any feedback on our support, please contact msdnmg@microsoft.com


这篇关于N-Tier Web-App - 乐观并发与last-update-wins ...需要时间戳吗? RowVersion?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆