简体   繁体   English

无法定义关系,因为它们已附加到不同的ObjectContext对象

[英]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.

相关问题 无法定义两个对象之间的关系,因为它们附加到不同的ObjectContext对象Entity Framework - The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects Entity Framework 无法定义两个对象之间的关系,因为它们附加到不同的 ObjectContext 对象 - The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects “无法定义两个对象之间的关系,因为它们被附加到不同的ObjectContext对象。” -错误 - 'The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects.' - Error 引发异常:因为两个对象附​​加到不同的ObjectContext对象,所以无法定义它们之间的关系 - Exception thrown: The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects EF4错误:无法定义两个对象之间的关系,因为它们附加到不同的ObjectContext对象 - EF4 error:The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects 实体框架v4 - 无法定义两个对象之间的关系,因为它们附加到不同的ObjectContext对象 - Entity Framework v4 - The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects 无法定义两个对象之间的关系,因为它们已附加到不同的ObjectContext对象 - The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects 实体框架:“无法定义两个对象之间的关系,因为它们附加到不同的 ObjectContext 对象。” - Entity Framework: “The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects.” 无法找出哪些两个对象附​​加到不同的ObjectContext对象 - Cannot figure out which two objects are attached to different ObjectContext objects InvalidOperationException由于存在不同的ObjectContext对象 - InvalidOperationException because of different ObjectContext objects
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM