[英]Relationship cannot be defined because they are attached to different ObjectContext objects
I don't know what i'm missing, as the same page_load is executed no matter how the page is called, but when i quit the page without saving anything, and then go back into the page, it seems like my context object is not able to retreive the usaved values like it does when i do save the changes before quitting the page, leading me to this exeption when i try to save from there : 我不知道我缺少什么,因为无论页面如何调用都会执行相同的page_load,但是当我退出页面而不保存任何内容,然后返回页面时,似乎我的上下文对象是当我退出页面之前保存所做的更改时,无法像以前那样获取已使用的值,当我尝试从此处保存时,将我引向了本例:
Unable to set the relationship between the two objects , as they are attached to different ObjectContext objects. 由于这两个对象已附加到不同的ObjectContext对象,因此无法设置它们之间的关系。
here is what i have in the page load : 这是我在页面加载中的内容:
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"];
}
}
I had this problem too, you probably need one of those two functions : 我也遇到了这个问题,您可能需要以下两个功能之一:
context.DBAccess.Attach(versionDemande);
or this one 或这个
versionDemande = this.context.DBAccess.ApplyCurrentValues<DAL.DBObjects.VersionDemande>("VersionDemande", versionDemande);
depending on how your objects are created/retreived on the page, i recommend you to put these into try catch at first, it will help you to see what is going on if they fail. 根据您在页面上创建/撤消对象的方式,我建议您首先将它们放入try catch中,这将帮助您查看失败后的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.