none
SharePoint 2010 BDC Update Method: The instance cannot be updated, because there have been changes to the original instance data.

    Question

  • Hey, 

    I have some BDC Entities all exhibiting the same problem, I'm struggling to get my head around it. 
    The GetItem, GetList, Create all work fine,  problem is specifically with the Update() method. 

    I'm using Linq to SQL:

            public static void Update(Country country)
            {
                using (S7SMS_DataDataContext dbupdate = new S7SMS_DataDataContext() { CommandTimeout = 36000 })
                {
                    var CountryQuery = (from ctry in dbupdate.Countries
                                        where ctry.CountryId == country.CountryId
                                        select ctry).Single();

                    CountryQuery.CountryName = country.CountryName;
                    dbupdate.SubmitChanges();
                }    
            }

    The instance cannot be updated, because there have been changes to the original instance data.

    Stack Trace:
    [InvalidOperationException: The instance cannot be updated, because there have been changes to the original instance data.]
       Microsoft.SharePoint.BusinessData.Runtime.AbstractEntityInstance.Update(Boolean compareHash) +18805661
       Microsoft.SharePoint.SPListDataSource.UpdateEntityInstance(String bdcid, SPListItem itemToUpdate, IDictionary dictFieldValues) +212
    
    [SPException: Failed to update a list item for this external list based on the Entity (External Content Type) 'Country' in EntityNamespace 'S7_SMS.DataLayer.Bdc.S7SMSBDC'. Details: The instance cannot be updated, because there have been changes to the original instance data.]
       Microsoft.SharePoint.WebPartPages.DataFormWebPart.UpdateCallback(Int32 affectedRecords, Exception ex) +24017721
       System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +4052212
       Microsoft.SharePoint.WebPartPages.DataFormWebPart.FlatCommit() +312
       Microsoft.SharePoint.WebPartPages.DataFormWebPart.HandleOnSave(Object sender, EventArgs e) +24
       Microsoft.SharePoint.WebControls.SaveButton.OnBubbleEvent(Object source, EventArgs e) +691
       System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +70
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981
    

    help? 

    Wednesday, March 13, 2013 4:13 PM

Answers

  • It's been a long time since I was unable to source help with a problem. 

    Posted this on LinkedIn, Here, Facebook to all my other sharepoint dev friends and even Reddit/r/sharepoint! 

    Managed to fix it myself though. 

    My ReadList() Method was running in the same datacontext instance as my update, Adding a new instance to the ReadList() (with a using) resolved the issue. 

    • Marked as answer by Rmathieson Thursday, March 14, 2013 1:18 PM
    Thursday, March 14, 2013 1:18 PM