捕捉Entity framework 6的详细异常提示
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                捕捉Entity framework 6的详细异常提示
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                采用
try{}catch (Exception e){throw;}不能捕捉到詳細異常提示, e.message的內容為"Validation failed for one or more entities. See 'EntityValidationErrors' property for more details."
如果需要獲取詳細的異常提示,采用
1 try 2 { 3 return base.SaveChanges(); 4 } 5 catch (DbEntityValidationException ex) 6 { 7 var errorMessages = ex.EntityValidationErrors 8 .SelectMany(x => x.ValidationErrors) 9 .Select(x => x.ErrorMessage); 10 11 var fullErrorMessage = string.Join("; ", errorMessages); 12 13 var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); 14 15 throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); 16 }?鏈接:?http://stackoverflow.com/questions/15820505/dbentityvalidationexception-how-can-i-easily-tell-what-caused-the-error
轉載于:https://www.cnblogs.com/ygfnet/p/4248642.html
總結
以上是生活随笔為你收集整理的捕捉Entity framework 6的详细异常提示的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: Matlab实现《追光者》简谱
 - 下一篇: C/C++使用openssl进行摘要和加