开发者

How do I handle a failed SubmitChanges in LinqToSql?

开发者 https://www.devze.com 2022-12-09 20:48 出处:网络
If the db.SubmitChanges failed for whatever reason, I want to return a failed message. DO I just catch the error or does the ConflictMode help开发者_开发知识库 here?The FailOnFirstConflict specifies

If the db.SubmitChanges failed for whatever reason, I want to return a failed message.

DO I just catch the error or does the ConflictMode help开发者_开发知识库 here?


The FailOnFirstConflict specifies that attempts to update the database should stop immediately. ContinueOnConflict specifies that all updates to the database should be tried.

The latter may lead to inconsistent results, depending on the type of save/update you are performing.

So unless this is not relevant to you, simply return the first error by using FailOnFirstConflict.


ContinueOnConflict will still rollback. It will, however, try to apply all the changes it can to the database. This means that you can catch and report all the conflicts, rather than just the first one.

There is code in the answers to another question that show you how to do this.

0

精彩评论

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