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时出现此错误 块