asp.net mvc4 在EF新增的时候报对一个实体或多个实体验证失败
//entity为空 是数据库上下文会验证实体验证 var entity = db.UserInfo.Where(u => u.Mobile == mobile).FirstOrDefault(); if (entity != null) { MobileLogModel.AddMobileLog(dvid, dvType, "用户注册", "手机已注册", "UserInfo-Register"); return Json(result, JsonRequestBehavior.AllowGet); } public static void AddMobileLog( string title, string msg) { using (Dao.GiftDBEntities db = new Dao.GiftDBEntities()) { //让db 不对实体验证 db.Configuration.ValidateOnSaveEnabled = false; Dao.MobileLog log = new Dao.MobileLog(); log.MobileLogID = Utility.GetGUID(); log.Createtime = DateTime.Now; log.Title = title; log.Content = msg; db.MobileLog.Add(log); db.SaveChanges(); //再让db对实体验证 db.Configuration.ValidateOnSaveEnabled = true; } }