Print Page | Close Window

Another ImportEntities bug?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2167
Printed Date: 05-Jul-2026 at 2:27am


Topic: Another ImportEntities bug?
Posted By: midnit
Subject: Another ImportEntities bug?
Date Posted: 17-Sep-2010 at 10:16am
MainEntityManager has a bunch of Entities. Change one of them, then import that newly changed Entity into TempEntityManager. Save with TempEntityManager. In the SaveCallback (the Entity says its Unchanged and has no value for OriginalValuesMap) go ahead and import the resultant entity back into MainEntityManager. Now look at this entity in MainEntityManager...
 
It has EntityState of Unchanged but it has OriginalValuesMap with data in it. So if you call RejectChanges it goes back to the original value from BEFORE the save. I do not think this is correct. Even if you call AcceptChanges after you import it does nothing and when you call RejectChanges it will revert to the wrong value from BEFORE the save. Currently to work around this I call RejectChanges BEFORE I import the newly saved Entity in MainEntityManager - this puts the OriginalValuesMap to null, then when you import its all good and RejectChanges works as expected.
 
It seems very wrong to me that you can have an Unchanged state yet have original values that differ from the current values.



Replies:
Posted By: midnit
Date Posted: 30-Sep-2010 at 6:12am

Am I to assume due to lack of response that no one at IdeaBlade cares?

Wasted my time, but thank you for yours.


Posted By: sbelini
Date Posted: 30-Sep-2010 at 5:12pm
Hi,
 
I could not reproduce your issue. Can you provide a reproducible test case?
 
By the way, below is the test I ran (against northwindIB):
 
  int employeeID = 1;
  var targetedEmployeesList = _em1.Employees
    .Where(emp => emp.EmployeeID == employeeID)
    .ToList();
  Employee anEmployee = targetedEmployeesList.First();
  anEmployee.FirstName = ModifyString(anEmployee.FirstName);
  _em2.ImportEntities(new Entity[] { anEmployee }, MergeStrategy.OverwriteChanges);
  var op2 = _em2.SaveChangesAsync();
  op2.Completed += (s, savedArgs) => {
    _em1.ImportEntities(savedArgs.Entities, MergeStrategy.OverwriteChanges);
    var myEmployeeBackToEM1 = _em1.Employees.With(QueryStrategy.CacheOnly).First();
    var nameBeforeRejectChanges = myEmployeeBackToEM1.FirstName;
    _em1.RejectChanges();
    var nameAfterRejectChanges = myEmployeeBackToEM1.FirstName;
    if (nameBeforeRejectChanges == nameAfterRejectChanges) {
      MessageBox.Show("Same values before and after RejectChanges");
    } else {
      MessageBox.Show("Values changed !");
    }
  };
 
 


Posted By: midnit
Date Posted: 04-Oct-2010 at 6:34am
To be honest that was over 2 weeks ago and I have moved far beyond this issue since we have a "workaround" in place. We do not have sql server of any form or northwind and the effort to locate, install, configure these and create an application that reproduces the problem is SO far outside my available time its not funny.


Posted By: midnit
Date Posted: 04-Oct-2010 at 6:59am
But despite the inability to reproduce the specific issue, why would the entity be able to be "Unchanged" but have original data, and if you rejectchanges on an entity that looked like that it recovers the original data...even though its in an "Unchanged" state. It seems something in the process of setting state, or somewhere, it should prevent the possibility of this mixed up circumstance to exist.
 
Is there a case where your object should says its "Unchanged" but have OriginalMappedValues? And those values are different then the entities current values? That does not match my idea of "Unchanged" but perhaps I am missing the Vision


Posted By: DenisK
Date Posted: 04-Oct-2010 at 1:15pm
midnit;

After drilling into it further, we've discovered that it is a bug. I assume that you're calling the import with MergeStrategy.OverwriteChanges, correct?


Posted By: midnit
Date Posted: 06-Oct-2010 at 12:38pm

Yes, that is correct.



Posted By: DenisK
Date Posted: 06-Oct-2010 at 3:29pm
midnit;

The bug has been fixed. I have an EAP for 6.0.6 here if you wish to download it. Let me know.



Print Page | Close Window