ado parent/child scenario advice needed

Discussion in 'ASP .Net' started by MattB, Apr 10, 2006.

  1. MattB

    MattB Guest

    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
     
    MattB, Apr 10, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. davout
    Replies:
    0
    Views:
    553
    davout
    Apr 18, 2004
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,134
    David Schwartz
    Dec 9, 2003
  3. Replies:
    2
    Views:
    612
  4. Noel Dolan
    Replies:
    0
    Views:
    238
    Noel Dolan
    Jul 18, 2004
  5. Bitswapper
    Replies:
    5
    Views:
    150
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page