Try our conversational search powered by Generative AI!

Dynamic data store samples error in UsingImplicitIdentity

Vote:
 

I'm looking at the DDS Samples for CMS 6 R2 and in the file UsingImplicitIdentity a person object is created and updated, and then that person object is saved to another instance of the same store. 

The comments in the code say that there should be two person-objects returned now since another store instance was used.

At first without regard to the samples i found this odd since the same person object is always used, and i would assume that in the end only one person-object would exist. 

And when running the code that happened - only one object was returned.

So I was hoping somebody could clarifiy why the comments state something else? Was this perhaps R1 behaviour?

 

#58112
Apr 13, 2012 10:08
Vote:
 

The reason that 2 objects should be stored is that the only way the DDS can do an update of an existing object is by locating the id of the existing object. If the object implements IDynamicData or has a property called Id (of type Guid or Identity) then the DDS will use that property when saving to look for an existing item in the database and then update it. If not then a DynamicDataStore instance caches the id's of all of the objects it loads and saves which means that if you use different instances to save the same object you should get duplicates.

What's going wrong here is that the sample Person class has been updated so it has an Id property which means when the name was updated to "Jeff" the DynamicDataStore instance was update the existing instance.

Remove the Id property (or create a new class without an Id property) and you should see the documented behaviour.

#58261
Apr 16, 2012 14:00
Vote:
 

Okay, that sounds more logical :-)

so there IS a bug in the sample code.

I think i also found another bug in MappingWithEPiServerDataContract.cs

// DateOfBirth should be the default value as it was not mapped and therefore not saved
            host.Out.WriteLine(loadedPerson.DateOfBirth);
    
here the loadedPerson.DateOfBirth actually does have a DateOfBrith which is the one set when saving the Person.

 

#58287
Edited, Apr 18, 2012 7:45
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.