对一个或多个实体的验证失败。有关详细信息,请参见“EntityValidationErrors”属性。

时间:2022-05-04 17:14:41
 
public void UploadEmployees(List<Employee> employees)
{
SalesERPDAL salesDal = new SalesERPDAL();
foreach (Employee emp in employees)
{
salesDal.Employees.Add(emp);
salesDal.Configuration.ValidateOnSaveEnabled = false;//增加这就就ok了
salesDal.SaveChanges();
}


}


由于用的是MVC4 ,不支持这样写 

public void UploadEmployees(List<Employee> employees)
{
SalesERPDAL salesDal = new SalesERPDAL();

salesDal.Employees.AddRange(employees);

salesDal.SaveChanges();



}