问题描述
当调用 DbContext.SaveChanges
时,我得到一个 DbUpdateException:
When calling DbContext.SaveChanges
, I get a DbUpdateException:
未处理的异常类型'System.Data.Entity.Infrastructure.DbUpdateException' 发生在实体框架.dll.附加信息:发生错误时更新条目.有关详细信息,请参阅内部异常.
不幸的是,没有内部异常(至少,就我所见).有什么办法可以确切地看到 SaveChanges
抛出异常的原因?至少,查看 SaveChanges 在发生错误时尝试更新的表会很有帮助.
Unfortunately, there is no inner exception (at least, not as far as I can see). Is there any way to see exactly why SaveChanges
threw an exception? At the very least, it would be helpful to see what table SaveChanges tried to update with when the error occured.
推荐答案
当真正的异常似乎在某处丢失时,最好的办法是打破每个异常.无论它是在某个地方被抓住或吞下,无论是在你够不着的地方,调试器都会崩溃,让你看看发生了什么.
When it seems that the real exception gets lost somewhere, your best bet is to break on every exception. Regardless of if it's catched or swallowed somewhere, in or out your reach, the debugger will break and allow you to see what's going on.
有关详细信息,请参阅此 MSDN 链接:
See this MSDN link for more info:
这篇关于查找 DBUpdateException 的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!