Getting Data out of the UnitOfWork

Posts   
 
    
Posts: 6
Joined: 23-Jun-2005
# Posted on: 23-Jun-2005 23:42:09   

I'm working on a shopping cart wizard feature for my website. Right now, it's in Wizard format, so the user goes through a few pages putting in the data that is necessary. I want to use the UnitOfWork to get all this data, and then save it all together at the end of the Wizard. Only problem is, that I have a summary page as my last page, and I don't want to have the UnitOfWork save until the user submits through this last page. Is there a way for me to get the data out of the UnitOfWork to show up on the Summary page prior to saving that data?

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 24-Jun-2005 00:12:40   

Ashik_Manandhar wrote:

I'm working on a shopping cart wizard feature for my website. Right now, it's in Wizard format, so the user goes through a few pages putting in the data that is necessary. I want to use the UnitOfWork to get all this data, and then save it all together at the end of the Wizard. Only problem is, that I have a summary page as my last page, and I don't want to have the UnitOfWork save until the user submits through this last page. Is there a way for me to get the data out of the UnitOfWork to show up on the Summary page prior to saving that data?

Aye, it's a bit convoluted though as the UnitOfWork really wasn't designed for read access. The UnitOfWork was designed to accumulate instructions to be performed against the database, not as a penultimate validation container.

That being said, I use it this way, wink but I have been considering creating a dedicated type for the purpose.

Anyway, you're looking for the GetEntityForInsert, GetCollectionForSave, GetFor methods of the class. They don't return entities or collections, but rather UnitOfWorkElement and UnitOfWorkCollectionElement types, which contain the entities and collections you're looking for. Unfortunately, you'll need to loop through the collections and test for types to find what you're looking for. I extended the UnitOfWork class to let me fetch entities or collections by type which works fairly well.

Jeff...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 24-Jun-2005 10:32:51   

Great tip, Jeff, that extending the UoW class! simple_smile

Frans Bouma | Lead developer LLBLGen Pro