Entity Collection bound to grid and row deletion

Posts   
 
    
Kirk
User
Posts: 22
Joined: 26-Apr-2004
# Posted on: 30-Apr-2004 00:15:09   

There seems to be some sort of anomaly when deleting rows from a grid bound to an EntityCollection. When deleting a row from the Windows Forms datagrid the row is deleted, but other bound grids (specifically Infragistics WinGrid) showing the same data do not reflect the row deletion.

When deleting a row from the Infragistics WinGrid the row does not appear to delete although the collection does remove the Entity, which cause problems with the grid later.

I noticed that in both cases EntityCollection2.RemoveAt is called, and RemoveAt differs slightly from the Remove method in that it does not contain the following two lines of code:

OnListChanged(index, ListChangedType.ItemDeleted); // remove subscribtion to the changed event. entityToRemove.EntityContentsChanged -= new EventHandler(EntityInListOnEntityContentsChanged);

When these lines were added to RemoveAt things appear to work as desired.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 30-Apr-2004 10:15:31   

This is a bug indeed, in the adapter's entity collection. SelfServicing's entity collection does contain this code. This went unnoticed as other grids remove the row themselves. Thanks for reporting simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 30-Apr-2004 12:15:40   

Fix is now available.

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 04-Feb-2005 00:35:17   

When I delete a row from the Windows datagrid, the line removed from the grid control, but after calling:

Adapter.UpdateMyCol(MyCol) on doesn't save the changed collection to the database.

When change an existing row(s), or add new ones, on saves the collection as expected.

I somewhere read, that the deletion requires som extra tasks, but i can't remember, where i read about it.

Can anybody help me?

Thanks

Gabor

Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 04-Feb-2005 01:24:15   

I tried the Adapter.DeleteEntityCollection(MyCol).

Interestingly, it removes all the items from the grid, but the removed ones - ie. works "inversly" as expected confused

Everything, that i deleted from the grid remained, everything that i leaved there is deleted.

Wow! simple_smile

Does anybody experiented this strange behaviour?

Thanks

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 04-Feb-2005 09:48:52   

Deleting an entity from a collection is just that: removing an entity from a collection. It doesn't delete the entity for you from the database, you explicitly have to delete it yourself, as deletes are irreversable, and deleting an entity from a collection can mean various things. (and for example the user clicks 'cancel' and the removal should be undone... which can't be done if the removed entity is removed from the DB the moment it is removed from the collection.

Frans Bouma | Lead developer LLBLGen Pro
Gabor
User
Posts: 97
Joined: 29-Jan-2005
# Posted on: 04-Feb-2005 12:10:06   

Thanks Frans,

and how can i delete them from the database? I apologize, if it is so obvious, but i didn't find the explanation in the docs, and in the forum.

Thanks

Gabor

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 04-Feb-2005 14:17:33   

DeleteEntity or Adding them to a collection and call DeleteEntityCollection or adding them to a unitofwork2 and call commit on that object simple_smile

Frans Bouma | Lead developer LLBLGen Pro