本文主要是介绍显示EF实体对象的详细错误信息 db.Entry(entity).GetValidationResult() 或 catch (DbEntityValidationException ex),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
方法一:在快速监视中查看db.Entry(entity).GetValidationResult()
public class NewsDal{public static News Add(News entity){using (CmsContext db = new CmsContext()){News news = new News();try{news = db.News.Add(entity);db.SaveChanges();}catch (Exception ex){throw new Exception(ex.Message);}return news;}}}
快速监视中查看:db.Entry(entity).GetValidationResult()
方法二:直接catch (DbEntityValidationException ex) 前提先引用:using System.Data.Entity.Validation;
public class NewsDal{public static News Add(News entity){using (CmsContext db = new CmsContext()){News news = new News();try{news = db.News.Add(entity);db.SaveChanges();}//catch (Exception ex)catch (DbEntityValidationException ex){throw new Exception(ex.Message);}return news;}}}
这篇关于显示EF实体对象的详细错误信息 db.Entry(entity).GetValidationResult() 或 catch (DbEntityValidationException ex)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!