I have two related (1-M) entities: TWell and TWellbore. The relations are defined as:
// If a well is deleted, ALL associated wellbores must be deleted (from database)
[ManyValuedAssociation([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAllRemoveOrphan, 'FWell')]
FWellbores: Proxy<TList<TWellbore>>;
and
// If a wellbore is deleted, the associated well (parent) must NEVER be deleted (from database)
[Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
[ForeignKey('FK_Wellbore_Well')]
[JoinColumn('ID_Parent', [TColumnProp.Required], 'ID')]
FWell: Proxy<TWell>;
I am using two TAureliusDatasets here: adsWell and adsWellbore, with adsWellbore linked to a dataset field in adsWell. When I delete a TWellbore from the child list (by adsWellbore.Delete) all is OK. If immediately thereafter I try to insert a new entity (by adsWellbore.Insert), I get a VersionedConcurrencyControl exception on the TWell (parent) entity:
Status code: 500
Error Code: VersionedConcurrencyControl
Could not perform database operation due to optimistic concurrency control. Entity class: "TWell", Id: "21FF2717-C66E-4719-B644-88CEEB73EFF0", Version: 2'.
I suspect it's caused by the CascadeTypeAll - [TCascadeType.Remove] in the child (TWellbore) to parent (TWell) association but I don't understand why/how as the TWell entity wasn't changed.
Or is it that inserting in adsWellbore, leaves adsWell in edit state and I must always post the 'top-level' dataset (i.e. adsWell)?
Either way, I am not sure how to solve this. Any suggestion is welcome!