ado parent/child scenario advice needed

M

MattB

Hi. I have an ecommerce application that has a shopping cart as many do.
I've created a way to automatically add other items to the cart if
certain items are added, like "Get a fee t-shirt if you buy this" kind
of stuff.
The DataTable that holds the cart items has a column for "ID" (primary
key) and parentID that references another item's ID for items added with
another, so they can be lumped together. This lets me delete both the
main item and the free t-shirt item if the main item is deleted.
The method I have to do this is pretty crude:

I in a DataTable DeleteCommand, I just create a dataview to find the
child items with a RowFilter: "parentID = " & e.Item.ItemIndex("ID") and
delete those too.

This has worked for a while, but a client was making an item that would
add another item that would add another item. So there is now a
recursive relationship and my delete logic fails leaving "orphaned"
items that have a parentID, but the parent item is gone. This violates
the business rules (no free t-shirt without qualifying item).

So is there a best practice for this kind of thing? I played with
DataRelations a little, but I always wound up violating constraints if I
added an item with no child. Maybe I'm just doing it wrong, but if
anyone has a suggestion or can point me to a good link that illustrated
a recursive delete from a datatable, I would certainly appreciate it.
Hope this made sense. Thanks!

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top