【发布时间】:2009-09-03 20:35:42
【问题描述】:
我目前正在使用实体框架并遇到了这个问题:
无法定义两个对象之间的关系,因为它们附加到不同的ObjectContext 对象。
对于页面加载顺序,我通过这个填充dropdownlists:
using (DatabaseEntities db = new DatabaseEntities())
{
MyDictionary = new Dictionary<Guid, Person>();
var List= from emp in db.Set select emp;
...
foreach (Employee emp in List)
{
MyDictionary.Add(emp.id, emp);
另一个功能是“下一步”按钮,用于关闭此页面并打开另一个页面。
private void StoreInfo()
{
Person theLead= MyDictionary[new Guid(this.Lead.SelectedValue)];
....
this.Selected.Lead= theLead;
我在这里存储了一个会话状态的字典
public Dictionary<Guid,Person> MyDictionary
{
get
{
return Session["MyDictionary"] as Dictionary<Guid,Person>;
}
set
{
Session["MyDictionary"] = value;
}
}
如何将每个人从第一个上下文中分离出来,以便继续在页面中进行验证?我试过了
db.Detach(emp)
之前
MyDictionary.Add(emp.id, emp);
但它没有用。
【问题讨论】:
标签: c# asp.net entity-framework