这是我的代码,我得到MetadataException未被用户处理。
“System.Data.Entity.Core.MetadataException”类型的异常 发生在EntityFramework.dll中但未在用户代码中处理
希望有人可以帮助我,谢谢!
[HttpPost]
public JsonResult UserRegistration(User u)
{
string message = "";
//Here we will save data to the database
if (ModelState.IsValid)
{
using (barometerDBEntities1 dc = new barometerDBEntities1())
{
//check username available
var user = dc.Users.Where(a => a.Username.Equals(u.Username)).FirstOrDefault();
if (user == null)
{
//Save here
dc.Users.Add(u);
dc.SaveChanges();
message = "Success";
}
else
{
message = "Username not available!";
}
}
}
else
{
message = "Failed!";
}
return new JsonResult { Data = message, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
}
}