Delete prefetched collection in gridview

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 16-Aug-2007 08:57:04   

Hi,

I have a Project. Each project can have contacts. Their relation is m:n and I have a inbetweentable having ProjectID and ContactID to combine them.

On my webpage I retrieve a project and prefetch the Contact EntityCollection via their n:m relation ... not via the relation inbetweentable.

This collection I bind to the datagridview. I tried the delete command button and it stated the collection was readonly. Is this because I didn't use the inbetweentable relation?

Also: If I do use the inbetweentable relation and I bind this collection to the datagridview, how do I make sure that the delete command does not remove the entity from the contact entity collection but actually just removes the row in the inbetweentable relation?

I hope it's a bit clear what I am trying to do here ... can anyone offer some help?

Best regards,

  • G.I.
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Aug-2007 09:15:04   

You should mnually handle the delete command and attempt to delete the in-between entity using the ProjectID and the ContactID. If you are using LLBLGenProDataSource, then set LivePersistence to false, and handle the PerformWork event to manually handle the delete command.

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 16-Aug-2007 10:35:46   

Ok ... this I get ... but if I add a button and a command ... and I try I remove the relation from the inbetweentable by removing it from the entitycollection there ... then after that how do I fire the PerformWork event then?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Aug-2007 10:54:34   

and I try I remove the relation from the inbetweentable by removing it from the entitycollection there

I'm not sure what do you mean here, but I ment you should execute a delete on the intermediate table.

... then after that how do I fire the PerformWork event then?

You should already be within a PerformWork event handler. What do you mean by "fire the PerformWork event"?

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 16-Aug-2007 11:29:07   

ok ... what I have done in previous tables:

For example: Project has Deliverables (1:n) relation I set the entitycollection of the llblgendatasource to this entitycollection and bind this to the grid. (Live persistance is false, use PerformSelect and PerformWork events of the llblgendatasource)

On there I just define a link button with the commandname Delete. When I click on this button on the row, it just deletes the row from the datagrid and fires the PerformWork event on the LLBLGenDatasource.

This doesn't work "automatically" with the inbetweentable (don't know the technical official word for such a table). So instead of giving the button the CommandName "Delete" I should give it another name? And then ... when does the performWork event of the LLBLGenDatasource fire?

  • G.I.
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Aug-2007 15:07:54   

When the Delete command fires, it should fire the PerformWork event, where you can capture the entity to be deleted and attempt to delete related entities in the intermediate table before deleting that entity.

Would you please post your PerformWork handler code?

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 16-Aug-2007 16:12:21   

PerformWork Handler code is simply commit the uow ... problem is, I don't want to delete the item of the contact collection, I just want to delete the relation.

So I can't use the Delete CommandName, but should use for example a button with DeleteRelation CommandName, pass via the CommandArgs the ID of the contact. Then in the datagrid_rowcommand I can find out which relation I should delete.

I think that after that I should just delete that one entity from the database and do a refetch on the datagrid?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Aug-2007 10:13:36   

PerformWork Handler code is simply commit the uow ... problem is, I don't want to delete the item of the contact collection, I just want to delete the relation.

In the PerformWork event handler, you can do whatever you want. i.e. you can choose not to commit the UnitOfWork, and execute whatever method you want.

G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 17-Aug-2007 12:39:55   

Ok ... I have changed what I did ... I used a collection prefetched directly via the relation and not prefetching the inbetween class.

What I did now was fetching them both and bind the datagrid to the inbetween class entitycollection.

After that it was simple to show the related data via Eval and I could simply use the delete command and the unitofwork contained the deletion of the row.

After that I just had to remove the item also from the collection in the datagrid rowdeletedCommand.

Tnx anywayz, because you've pointed me already in a good direction for another somewhat related problem at another place simple_smile

  • G.I.