Template: adapter.
Hi,
We have a hierarchy with CargoOperation as a super-type and Loading and Discharging as sub-types of CargoOperation. The inheritance type is Target per Entity. We create some new Loading entities and some new discharging entities. The problem occurs when we try to save the entities:
foreach (DischargingEntity dischargingEntity in dischargings)
{
adapter.SaveEntity(dischargingEntity,false,true);
}
Or just:
adapter.SaveEntityCollection(dischargings, false, true);
This works. But then we try to save the Loading entities the same way and we get this error:
“An exception was caught during the execution of an action query: Violation of UNIQUE KEY constraint 'IX_cargo_operation'. Cannot insert duplicate key in object 'dbo.cargo_operation'.”
Ok. When we do it the opposite way (create entities of booth types, and save the Loading entities first and Discharging entities last), the same error now occurs for the Discharging entities.
I have no clue what the problem is. Anyone who can help?
Ps: A lot of the fields for the different entities are the same for all the CargoOperations we inserts – booth the Loading and the Discharging entities - (especially the foreign keys to other tables like Cargo, Fixture etc…).
Ps2: The entities are transformed to xml and then transformed back to objects before they are inserted in the database.