首先的實體,錯誤是錯誤,同時還與關係
「的實體對象不能被IEntityChangeTracker的多個實例可以參考」我有兩個實體用戶& UsersInHospitals
這是我如何創建一個新的帳戶用戶
var user = new User(); user.UserID = Guid.NewGuid(); user.Address = employmentAddress.Trim(); user.ZipCode = int.Parse(zipcode.Trim());
UsersInHospital hospitalAff;
hospitalAff = new UsersInHospital()
{
UserID = user.UserID,
HospitalID = Guid.Parse(hospitalAff1),
IsEmployed = Boolean.Parse(isEmployed1)
};
user.UsersInHospitals.Add(hospitalAff);
hospitalAff = new UsersInHospital()
{
UserID = user.UserID,
HospitalID = Guid.Parse(hospitalAff1),
IsEmployed = Boolean.Parse(isEmployed2)
};
user.UsersInHospitals.Add(hospitalAff);
,並將其保存
_db.AddToUsers(user);
return _db.SaveChanges(); //THIS LINE GIVES ME ERROR
我正在使用實體框架4.我懷疑我將不得不爲每個醫院實體單獨創建變量