後成爲空我有我的ASP.Net項目導航屬性使用條款
有兩種foreignkeyconstructs內的數據庫實體模型,無論是ID在所示關係之間的結構。
現在我想用下面的方法
IntraNetEntities entities = new IntraNetEntities();
if (entities.EmployeeList.Count() == 0)
{
using (entities)
{
for (int i = 0; i < 100; i++)
{
EmployeeList newEmployeeList = new EmployeeList()
{
department = "Standardabteilung",
mobile = i,
landline = 1 + i,
mail = "Standardemail",
position = "Standardfunktion",
shortcode = "abc",
lastname = "StandardNachname",
roomnumber = Convert.ToDouble(i),
firstname = "Standardvorname"
};
PrivateContact newPrivateContact = new PrivateContact()
{
city = "Standardstadt",
country = "deutscheland",
landline = i,
mail = "standardemail",
mobile = i * 2,
street = "standardstreet",
zip = i * 10,
EmployeeList = newEmployeeList
};
WorkContact newWorkContact = new WorkContact()
{
city = "Standardstadt",
country = "deutscheland",
landline = i * 9,
mobile = i * 12/8,
mail = "standardmail",
street = "standardstraße",
zip = i * 9,
EmployeeList = newEmployeeList
};
newEmployeeList.PrivateContact = newPrivateContact;
newEmployeeList.WorkContact = newWorkContact;
entities.AddToEmployeeList(newEmployeeList);
entities.AddToPrivateContact(newPrivateContact);
entities.AddToWorkContact(newWorkContact);
}
entities.saveChanges();
return true;
}
}
else
{
return false;
}
我的問題是增加100個樣本項目,我的導航屬性時,這個方法結束消失! 它們在調試時看起來都很好,但仍然處於使用案例中,但之後它們都是空的,沒有對這些值做任何更改。
如何保持導航值?
謝謝
只是讓我明白 - 你的意思是,新的聯繫人和僱員的名單AREN」 t被持久化到數據庫?或者,newPrivateContact.EmployeeList正在失去它的價值併成爲空(如果這就是你的意思,你如何在使用之外訪問newPrivateContact,因爲它的範圍在使用範圍內)?或者是其他東西? – mjwills
我只想保留導航屬性。我的意思是newPrivateContact.EmployeeList和/或newEmployeeList.PrivateContact正在失去它們的價值!鑑於newEmployeeList和newPrivateContact都是在使用子句 – Evils