Persisting Entity Collections (Web)

Posts   
 
    
lotek
User
Posts: 56
Joined: 14-Sep-2005
# Posted on: 26-Apr-2006 04:22:27   

I want to store my entity collection in viewstate and persist the changes all at once when a user clicks a save button. Has anyone done this sucessfully?

Lets say im binding a datalist to an entity collection. These are the steps i have mapped out so far:

  1. Add the entity to the llblgen designer and specify any fields on relations. (so i can display foreign key values)

  2. Fetch an entity collection using a prefetch path for the appropriate related fields.

  3. Bind the collection to the datalist and store the entitycollection in viewstate.

  4. Make changes to the entity collection based on datalist insert/edit/delete events.

  5. Save the entity collection to persist the changes back to the database.

But i have some concerns, this isnt water tight quite yet. What about showing the related fields for new rows, could i refetch just the related fields, or maybee i would have to use some type of additional lookup collection? Also how could multiple new rows be refrenced in an entity collection since they would most likely not have a primary key yet.

Just wondering if anyone has accomplished something like this. Thoughts?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 26-Apr-2006 11:08:29   

To track work, you should use a UnitOfWork object, and store that in the viewstate (or better: session).

Also, a new entity doesn't exist in the db yet, so it by definition doesn't have related entities in the db.

Frans Bouma | Lead developer LLBLGen Pro
lotek
User
Posts: 56
Joined: 14-Sep-2005
# Posted on: 26-Apr-2006 17:11:18   

One thing that im still fuzy on is how the unitofwork object would work when databinding. The datalist for example requires a postback and rebinding to edit a row. Wouldnt i need a way to merge the changes in the unitofwork object with the original datasource so any user modifications are reflected in the datalist's output?

In terms of related entities, i guess i just have some lookup tables. So i could fetch those seperatly i suppose and lookup the value for the new entities.

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 27-Apr-2006 08:07:25   

Wouldnt i need a way to merge the changes in the unitofwork object with the original datasource so any user modifications are reflected in the datalist's output?

I guess it's the other way around. All you have to do is update the UOW with changes made to the original datasource.

lotek
User
Posts: 56
Joined: 14-Sep-2005
# Posted on: 27-Apr-2006 23:49:56   

Well, say the page makes a postback, i save my changes to the UOW object and store the UOW object in the viewstate (becuase i dont want to make the changes yet) Now i have to rebind my datalist, datagrid, whatever... Problem is i dont have a datasource that reflects the changes that are stored in the UOW object. Does that make sense?

I did some crawling through the archives and found some answers. I guess the consensus is that LLBLGen isn't really designed to support the PL and something like this really needs to be implemented manualy. But if anyone has a suggestion on best practices for this situation im all ears. smile

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 28-Apr-2006 03:12:41   

Well usually controls will use the viewstate to maintain their state during a postback. The UoW should be used to maintain changes that you will want to persist to the database. Like you said the UoW isn't really there to maintain the presentation. You can keep it in session from request to request and the committ it when you want too. What is losing it's value after the postback?

lotek
User
Posts: 56
Joined: 14-Sep-2005
# Posted on: 28-Apr-2006 08:02:47   

Lets take an example:

  1. Bind a datalist to a datasource.
  2. Make changes to the datalist and postback.
  3. Save changes to the UOW object.
  4. Rebind the datalist
  5. Make changes and postback.
  6. Save change to the UOW object.
  7. Commit changes.

On step four i want to rebind the datalist to a source that reflects the changes in the UOW object. Since i haven't (and dont to) commit the UOW object yet, the changes are not yet reflected in the database. So i dont have a datasource that accurtaly reflects what the data will be once it is saved. Make sense? Its like i would have to somehow merge the pending changes in the UOW object with the original datasource.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Apr-2006 14:40:23   
  1. Bind a datalist to a datasource.
  2. Make changes to the datalist and postback. (changes are maintained in the datalist after the postback, just make sure your control's EnableViewState property is set to true)
  3. Save changes to the UOW object.
  4. Rebind the datalist (you don't need this step)
  5. Make changes and postback.
  6. Save change to the UOW object.
  7. Commit changes.
lotek
User
Posts: 56
Joined: 14-Sep-2005
# Posted on: 28-Apr-2006 18:01:03   

As far as i know you have to rebind a datalist/grid etc when putting a row into edit mode or taking it out of edit mode. So seems like step 5 would be required. Think about if i was adding a new row to the datalist, if i didnt rebind the grid, the new row wouldnt exist.

Posts: 14
Joined: 16-Mar-2007
# Posted on: 19-Mar-2007 15:42:57   

Does someone has got the solution for it.

I wanted to maintain the same in one of my screen to store the data in collection before saving

lotek wrote:

As far as i know you have to rebind a datalist/grid etc when putting a row into edit mode or taking it out of edit mode. So seems like step 5 would be required. Think about if i was adding a new row to the datalist, if i didnt rebind the grid, the new row wouldnt exist.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Mar-2007 09:47:53   

I'll close this thread, it's an old thread, please create a new thread for your questions. Follow the guidelines posted here: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7722

To answer your question, use the LLBLGenProDataSource. (check the LLBLGen Pro manual)