Exceptions by DataContext

2019-02-04 11:41发布

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)

2条回答
叛逆
2楼-- · 2019-02-04 12:28

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.

查看更多
Anthone
3楼-- · 2019-02-04 12:29

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
查看更多
登录 后发表回答