Version control with Master-Detail in XData

Hi Wagner,

I experienced issues continuing on another ticket (VersionedConcurrencyControl error when adding a child entity (after deleting one)) regarding this issue, so I decided to create a new topic. Hopefully you can help me out here. This issue is eating my lunch by now :frowning:

The problem I’m facing can be reproduced in the attached demo app. Unzip to a folder and build VersionDemo_Server and VersionDemo. Both will created in Win32 subfolder which has a sample SQLite database - with some test data - included.

Run the server and app and you’ll see a grid with some sample invoice data. Select invoice no 2 and click the Edit button. Now you have a form with the invoice, a 1-1 record (Info) and 1-M (Items).
You can edit all you want in the grid and everything is OK. However, editing in the grid will put the Invoice (parent) dataset also in Edit Mode. The problem starts when you save the entire invoice. Check the yellow edit and yellow grid column; the row version of the TInvoice entities go out of sync (i.e. fall behind on the updated Invoice row version, which will be incremented). If you now edit and attempt to post an Invoice Item in the grid, you’ll get the Concurrency exception.

I have attempted many things like:

  • Omitting the parent reference field from the child data set. It alleviates the problem, but only for editing. When inserting/appending, this doesn’t work because you cannot set the parent reference (i.e. InvoiceItem.Invoice).

  • Various Cascade options, but no luck…

I’m assuming the solution lies in either setting the correct cascade options or in somehow refetching the parent reference entities (in Items) to ensure the Version field is updated. However, I’m out of options and probably no longer “seeing the forest through the trees” so hopefully you can give me some clue(s). Ideally, I want one Save/Cancel button combination for the entire form.

VersionDemo.zip (177.0 KB)

PS: Apologies for the Invalid Pointer exception when closing (destroying) the Invoice form but I couldn’t figure this out quickly and want to make progress on the real application.