CSLA 4, EF 4 - Implementation question

CSLA 4, EF 4 - Implementation question

Old forum URL: forums.lhotka.net/forums/t/9093.aspx


joemorin73 posted on Wednesday, June 16, 2010

I'm currently working on a project using CSLA4 and EF4 to create a custom shopping cart system for an online registration system.  Everything is coming along pretty well, but I seem to be stumbling a bit on how to approach the check out system.

Background

The client requires the cart to contain items that can differ not only in product, but in class type all together.  These items can differ so extensively, including different order systems.  When the cart has received payment, the cart is to be closed and registration records must be created in the appropriate tables based on the type of Item.  If any problem occurs during this process, the cart must rollback undoing any of the changes.

So far, so good.

Most of this has been figured out, but I will include some details to help show the problem.

The cart contains the status and a collection of readonly cart items.  Each cart item is a common object that can be used to call up the appropriate item.  For each type of Item, we've created a different class.  (IE, For a member registration, we have a member class.  For a clinic registration, we have a clinic class.) 

The cart "commits" its items to the tables dynamically by calling each Item through a common ICartItem interface.  (Sidenote: DataPortal was a good demonstration on how to call methods of different items without knowing what they were until runtime.  Thanks Rocky!)  In this case, I call ICartItem.CommitToFinal for each Item.

Problem

Transaction and Rollback.

As I'm looping through each Item, my short version of ICartItem.CommitToFinal implementation in most classes is as follows:

  1. Get Existing or Instantiate New Record for Final
  2. Copy Information from CartItem to Final
  3. Save
  4. Copy references from Final into CartItem

After the save, I need to copy information from the final back into the cart items as well as make some links within the final after the save.  (Final's DB design uses autonumber identity, I can't change this.)

What I'm looking for is how to save, without saving.  I know this can be done on a per item basis.  IE, My CartItem and all its children are enclosed in a transaction on a DataPortal call.  How do I approach this since each item is it's own EditableRoot making it's own DataPortal calls?

Unless I answered my question.  Do I make the root items switchable and add them to a Collection and have to collection commit the items?  Is there another approach?

Thank you.

Copyright (c) Marimer LLC