Cascading Inserts/Updates

Sep 5, 2010 at 4:54 PM

I've just been trying out cascading inserts and couldn't get it to work so I have been looking at the code. The issue workitems for cascading inserts and updates were closed stating these were implemented in changeset 75707 but no change was committed in that changeset or any later ones that would achieve this. In the current repository version the code for cascading inserts has a few "TODO" comments in it and the code to perform an insert query is unreachable and there does not appear to be any code in SqlCeDataStore to handle cascading updates whatsoever.

Is this simply a case of the required changes being missed in the recent large merge, similar to the leftover redundant file which was later removed?

Coordinator
Sep 7, 2010 at 2:45 PM

Do you have a specific use-case in mind for these (i.e. a simple project)?  I did implement cascading at least for the use-case I have.  I'll verify that change actually ended up in the Codeplex code.

Sep 7, 2010 at 3:17 PM

My initial attempt at this was an extremely simple case using 2 entities, EntityA which contained an array of type EntityB with the Reference attribute against it, I populated the data, inserted EntityA into the database using the SqlCeDataStore.Update(object, bool insertReferences) override to specify cascading inserts, EntityA ended up in the database but the EntityB table was entirely empty.

Looking at the source code for SqlCeDataStore in codeplex at lines 868-889, this is the loop that should be inserting the references, it sets a bool isNew to false, then has a switch statement where none of the cases have any implementation (both have TODO comments) and only inserts the reference if isNew is true, with the codeplex code it is impossible for isNew to ever be true. This is why I suspected it got missed in a merge.

With the Update() method in the codeplex SqlCeDataStore there isn't an override to specify cascading updates at all and no reference at all in the implementation of this method to reference fields.

I can look at creating a simple project to demonstrate this but looking at the code as mentioned above it is reasonably clear what will happen.

Coordinator
Sep 7, 2010 at 3:19 PM

No, your description is clear enough.  I'll take a look.

Coordinator
Sep 8, 2010 at 2:30 PM

Take a look at my check-in yesterday and see if it works for you.

Sep 9, 2010 at 8:29 AM

Thanks I'll give that version a go shortly.

Is there any update on cascading updates? The old issue (#27942) was closed saying this was implemented in changeset 75707 but this didn't seem to make it into the codeplex tree either.

Coordinator
Sep 13, 2010 at 5:15 PM

Ni idea why I marked it as complete with changeset 7507 - it certainly wasn't.  The changeset I just checked in adds some cascading insert/update capabilities.  See if it does what you're after (I think it covers your test case anyway).

Sep 19, 2010 at 4:14 PM

I've finally had a chance to try this and I can confirm that cascading inserts now works for me with the cases I've tried so far, thanks.