DataContext 的异常

发布于 2024-09-03 01:20:59 字数 379 浏览 3 评论 0原文

我一直在互联网上进行一些搜索,但似乎找不到遮阳篷。 DataContext 可以抛出哪些异常?或者更具体地说,DataContext.SubmitChanges() 方法会抛出哪些异常?

编辑
作为参考,这里列出了 L2S DataContext 可能引发的已知异常:

  • SqlException
  • ChangeConflictException
  • DuplicateKeyExceptionforeignKeyReferenceAlreadyHasValueException
  • OutOfMemoryException
  • (当未正确处置 DataContext 时)

I've been doing some searching on the internet, but I can't seem to find the awnser. What exceptions can a DataContext throw? Or to be more specific, what exceptions does the DataContext.SubmitChanges() method throw?

EDIT
For reference, here a List of possible known exceptions that could be thrown by the L2S DataContext:

  • SqlException
  • ChangeConflictException
  • DuplicateKeyException
  • ForeignKeyReferenceAlreadyHasValueException
  • OutOfMemoryException (when not correctly disposing the DataContext)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

只为一人 2024-09-10 01:20:59

你是对的,MSDN 在这里并没有多大帮助。这是我从头到尾记得的:

  • SqlException(来自 ADO.NET 层)
  • ChangeConflictException (L2S)
  • DuplicateKeyException (L2S)
  • 任何自定义覆盖(部分 void OnXXXEntity)可能引发的异常

You're right, MSDN is not a great help here. This is what I can remember from the top of my head:

  • SqlException (from the ADO.NET layer)
  • ChangeConflictException (L2S)
  • DuplicateKeyException (L2S)
  • Anything that cusomized overrides (partial void OnXXXEntity) may raise
凡尘雨 2024-09-10 01:20:59

嗯,当错误发生在数据库级别时,存在底层数据库异常(我认为是 SqlClientException 类型)。当它检测到另一个用户的并发更改时,它会抛出 ChangeConflictException。可能还有其他方法取决于值是否为空(当它不应该为空时),诸如此类的事情。许多错误与上下文本身无关。

HTH。

Well, there are underlying database exceptions (I think of type SqlClientException) when the error occurs at the database level. There is the ChangeConflictException that it throws when it detects a concurrent change by another user. There may be others depending on whether a value is null when it shouldn't be, that sort of thing. A lot of the errors are unrelated to the context itself directly.

HTH.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文