Wondering if anyone has any tips on this...
I have a Product table, and a Component table. Component is subclassed, with discriminator ComponentType. Have a ProductComponent table which is many-to-many
In my product mapping, I created bags of components
Code:
<bag name="Widgets" table="ProductComponent">
<key column="ProductId" />
<many-to-many class="Widget" column="ComponentId" where="ComponentType=1" />
</bag>
<bag name="Gizmos" table="ProductComponent">
<key column="ProductId" />
<many-to-many class="Gizmo" column="ComponentId" where="ComponentType=2" />
</bag>
This works, except for when I need to clear, or mostly clear my collection from the Product. In that situation, a single delete command is issued. DELETE FROM ProductComponent WHERE ProductId=@p0. Then it re-inserts the new ones, but has deleted all the existing collections that didn't get updated.
It seems like in order to get the Delete statement to include the ComponentType, I'd need to put a where on the bag, but that wants a ComponentType on the association table then.
Anyone have any ideas on how to better accomplish this?