无法隐式转换类型' System.Data.Entity.Validation.DbEntityValidationException'到' System.Exception'

时间:2015-07-09 09:31:16

标签: c# entity-framework

try
{
    using (var context = new DbContext())
    {
        context.Contracts.Add(_contract);
        context.SaveChanges();
    }
}
catch (System.Data.Entity.Validation.DbEntityValidationException ex)
{                
    foreach (var validationErrors in ex.EntityValidationErrors)
    {
        foreach (var validationError in validationErrors.ValidationErrors)
        {
            string message = string.Format("{0}:{1}",
                validationErrors.Entry.Entity.ToString(),
                validationError.ErrorMessage);                       
        }
    }
    throw;
}   
  

//错误:"无法隐式转换   类型' System.Data.Entity.Validation.DbEntityValidationException'            到' System.Exception'" //在Catch中使用System.Data.Entity.Validation.DbEntityValidationException时出现此错误   块

0 个答案:

没有答案