[英]The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects Entity Framework
[英]Relationship cannot be defined because they are attached to different ObjectContext objects
我不知道我缺少什么,因为无论页面如何调用都会执行相同的page_load,但是当我退出页面而不保存任何内容,然后返回页面时,似乎我的上下文对象是当我退出页面之前保存所做的更改时,无法像以前那样获取已使用的值,当我尝试从此处保存时,将我引向了本例:
由于这两个对象已附加到不同的ObjectContext对象,因此无法设置它们之间的关系。
这是我在页面加载中的内容:
public partial class FraisDeplacement : System.Web.UI.UserControl
{
BLL.SessionContext context;
DAL.DBObjects.VersionDemande versionDemande;
protected void Page_Load(object sender, EventArgs e)
{
this.context = (BLL.SessionContext)Session["sessionContext"];
this.Page.LoadComplete += new EventHandler(Page_LoadComplete);
versionDemande = (DAL.DBObjects.VersionDemande)Session["versionDemande"];
}
}
我也遇到了这个问题,您可能需要以下两个功能之一:
context.DBAccess.Attach(versionDemande);
或这个
versionDemande = this.context.DBAccess.ApplyCurrentValues<DAL.DBObjects.VersionDemande>("VersionDemande", versionDemande);
根据您在页面上创建/撤消对象的方式,我建议您首先将它们放入try catch中,这将帮助您查看失败后的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.