Recursive Save Missing an entity

Posts   
 
    
mprothme avatar
mprothme
User
Posts: 78
Joined: 05-Oct-2017
# Posted on: 07-Oct-2019 23:44:12   

We're currently using version 5.5 (5.5.0) RTM, Build Date: 02-Nov-2018

Our application has the following table structure

  • Trade
  • Trade Detail (m:1) relationship to trade, this relationship is not optional
  • Trade Price (m:1) relationship to Trade Detail, this relationship is not optional (m:1) relationship to Calculated Value, this relationship is optional
  • CalculatedValue
  • CalculatedValueVariable (m:1) relationship to CalculatedValue, this relationship is not optional

We have a process that builds out a full structure similar to as follows

A trade record with 1 or more details Each detail has 1 or more prices Each price ties to 1 calculation. For the purposes of this process, the calculation is unique to the price, even though the relationship does not require it to be (a single calculation could point to more than one trade price in theory). Each calculation has multiple variables tied to it.

This process happens several times and then we call adapter.SaveEntityCollection(toSave, true, true) on the results to save recursively and refetch. The adapter is an instance of IDataAccessAdapter.

What we've found is that all of the entities get saved and can be queried in the database individually. Additionally I can look through the structure in the debugger and see id values on all of the items in memory. For some reason however, the connection between Trade Price and Calculation (a foreign key column called CalculatedValueId) isn't set in the database.

Even more odd, is that after the save the CalculatedValueId is set on the TradePrice object and it ties to a record in the database (if I query through sql), its just that the same column on the trade price record in the database is null.

If we call adapter.SaveEntityCollection(toSave, true, true) a second time then the connection is persisted to the foreign key column in the database.

Can you speak to what we're missing? Thanks!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39570
Joined: 17-Aug-2003
# Posted on: 08-Oct-2019 10:27:23   

v5.5.0 had some issues, e.g.

Fix Runtime Libraries 5.5 5.5.1 12-Dec-2018 When an FK field is re-used in multiple relationships and also is a PK field in another relationship, setting the FK field could cause a desync of the wrong related entities

and

Fix Runtime Libraries 5.5 5.5.1 28-Dec-2018 If multiple distinct graphs are present in a unit of work, it could be not all entities are inserted

SaveEntityCollection uses a uow, so you might run into this problem. These issues stem from the batching implementation where in some edge cases things could go wrong. Could you try v5.5.1 please?

Frans Bouma | Lead developer LLBLGen Pro