首页 > Windows开发 > 详细

C# EF entity更新异常捕捉

时间:2019-06-17 11:13:22      阅读:148      评论:0      收藏:0      [点我收藏+]
技术分享图片
 1  try
 2 {
 3 ......
 4 }
 5             catch (DbEntityValidationException exc)
 6             {
 7                 // just to ease debugging
 8                 foreach (var error in exc.EntityValidationErrors)
 9                 {
10                     foreach (var errorMsg in error.ValidationErrors)
11                     {
12                         // logging service based on NLog
13                         Console.WriteLine($"errorMsg: {errorMsg.ErrorMessage}; PropertyName = {errorMsg.PropertyName}");
14                     }
15                 }
16 
17                 throw;
18             }
19             catch (DbUpdateException e)
20             {
21                 foreach (var result in e.Entries)
22                 {
23                     Console.WriteLine($"Type: {result.Entity.GetType().Name} was part of the problem. ");
24                 }
25                 throw;
26             }
27             catch (Exception e)
28             {
29 
30                 throw;
31             }
View Code

 

C# EF entity更新异常捕捉

原文:https://www.cnblogs.com/RocCnBlog/p/11038619.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!