开发者

How do I handle a failed SubmitChanges in LinqToSql?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜