开发者

How can we handle concurrency errors in LINQ to SQL?

How can开发者_如何学运维 we handle concurrency errors in LINQ to SQL?


One way is by setting the modes on each column for how it participates in conflict checking. There are three options: Always, Never & WhenChanged

For more info, check here and here

Also an option is using the ConflictMode parameter to SubmitChanges (one of ConflictMode.ContinueOnConflict or ConflictMode.FailOnFirstConflict. If you set it to the former, the commit will throw when complete, but you will have a collection of failed submissions for further processing... see this answer for more info.


To handle the concurrency conflicts, one should use the try and catch block in the updataion LINQ to catch the "ChangeConflictException". Once you got the exception, loop throuh changeConflicts collection to way of resolving the problem (KeepCurrentValues, OverwriteCurrentValues and KeepChanges). It would be better,if we are checking the concurency check at field level.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜