using grid to insert an entity into a collection in memory?

Posts   
 
    
nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 25-Apr-2008 15:52:28   

I am trying to use the rad grid insert mode to create an entity which i will add to a collection of entities in memory rather than inserting to a data store.

Is there any way with the LLBLGenProDatsSource to halt the insert to the database ( the entity.Save() method) and merely take the newly created entity and add it to a collection for persistence in some other form to be dealt with later?

Attachments
Filename File size Added on Approval
AnswersGrid.zip 1,964 25-Apr-2008 15:53.16 Approved
daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Apr-2008 04:08:35   

Hi nilsey, this is what you should do:

  1. Set _yourLLBLGenProDataSource _property to false.

  2. Create event handlers for _PerformSelect _and _PerformWork _ events (for help on this read LLBLGenPro Help - Using the generated code - Databinding at designtime and runtime - Databinding with ASP.Net 2.0 - Usage examples)

  3. At your _PerformWork _method use the new entities and add them to your special collection:

protected void yourLLBLGenProDataSource_PerformWork(object sender, PerformWorkEventArgs e)
{
    // iterate through newly entities
    foreach (UnitOfWorkElement element in e.Uow.GetEntityElementsToInsert())
    {
        SomeEntity entityToAdd = (SomeEntity) element.Entity;
        yourCollection.Add(entityToAdd);
     }
}

And that's all. As you aren't committing the UOW (_uow.Commit()_) the collection wont be persisted.

David Elizondo | LLBLGen Support Team
nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 26-Apr-2008 17:34:27   

daelmo wrote:

Hi nilsey, this is what you should do:

  1. Set _yourLLBLGenProDataSource _property to false.

i have a feeling you meant to write a property name in there!??

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 26-Apr-2008 19:18:38   

Sorry stuck_out_tongue_winking_eye The property is yourLLBLGenProDataSource.LivePersistence = false

David Elizondo | LLBLGen Support Team
nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 29-Apr-2008 02:29:08   

Thanks that worked for the inserts from the data grid. however the updates are not being caught. Is there another setting to enable the updates or is there something i am missing?

i have included the code as an attachment.

Attachments
Filename File size Added on Approval
AnswersGrid.zip 3,034 29-Apr-2008 02:29.17 Approved
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 29-Apr-2008 09:13:26   

I'm surprised the perform work is called in Inserts, cause the event is not defined in the aspx datasource declaration code:

<llblgenpro:LLBLGenProDataSource runat="server" ID="LLBLGenProDataSource_Answers" LivePersistence="false" DataContainerType="EntityCollection" EntityCollectionTypeName="VSurvey.DAL.CollectionClasses.AnswerCollection, VSurvey.DAL"> </llblgenpro:LLBLGenProDataSource>

Also I guess you don't need to do any coding in the case of updates, coz the collection should be updated automatically. (no need for remove and insert).

nilsey
User
Posts: 54
Joined: 11-Jan-2008
# Posted on: 29-Apr-2008 18:31:37   

Walaa wrote:

I'm surprised the perform work is called in Inserts, cause the event is not defined in the aspx datasource declaration code:

<llblgenpro:LLBLGenProDataSource runat="server" ID="LLBLGenProDataSource_Answers" LivePersistence="false" DataContainerType="EntityCollection" EntityCollectionTypeName="VSurvey.DAL.CollectionClasses.AnswerCollection, VSurvey.DAL"> </llblgenpro:LLBLGenProDataSource>

Also I guess you don't need to do any coding in the case of updates, coz the collection should be updated automatically. (no need for remove and insert).

what i am experiencing is that updates are working only for entities that have been retrieved from the datastore (IsNew = False).

the current flow of my control is: -> Entity collection retrieved from data store. -> Assigned to LLBLGenProDS with livepersistence = false on perform select -> These entities can be edited in the rad grid, the update commend fired the PerformWork method and i handle the changes there. -> new entries in the rad grid show up in the LLBLGenProDS.Entities collection as new entities (with Isnew = True, and the prikmary key ID set to 0). -> the new entities are edited in the gird but on the Update command, the PerformWork method is not fired and i can't handle the changes.

Again i am submitting a sample of the code. (it is the second radgrid -llblgenprodatasource pair which currently is functioning as my POC test bed.)

is there something that i need to set or handle in the update process or on the insert process to allow the LLBLGenProDataSource to fire the PerformWork on update of entities with IsNew?

Attachments
Filename File size Added on Approval
AnswersGrid.zip 3,291 29-Apr-2008 18:33.21 Approved
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Apr-2008 10:54:59   

I'm still surprised as the LLBLGenProDataSource declaration should contain the following: OnPerformWork="LLBLGenProDataSource_Answers_PerformWork"

Anyway I think you don't need to use Me.Answers collection as a storage for your entities, as they are already stored in LLBLGenProDataSource_Answers.ContainedCollection

Which I think should get the updated values automatically from the bound grid. So you don't need to trap an event for it.

You can make a little test, place a button on the form, after editing a new entity in the grid press the button, and in the button click handle check the LLBLGenProDataSource_Answers.ContainedCollection contains the new values or not.