EntityCollection.Remove(entity)...makes System hang!

Posts   
 
    
LLBLGen
User
Posts: 43
Joined: 10-Apr-2006
# Posted on: 13-Apr-2007 15:00:05   

i have infragistics grid where user can select multiple rows and delete items by rt clicking the "delete rows" option . The datasource of the grid is an entitycollection. when multiple rows are selected and "delete rows" is clicked...i am collecting each of the entity from selected row to a "temp" entitycollection, deleting it from the DB and finally removing it from the entitycollection that is the datasource.

But on the last entity the system freezes on EntityCollection.Remove(entity). statement...like its going on a infinite loop. here is the actual code.



        EntityCollection<CustomerMarkUpEntity> CustomerMarkUpCollection = new EntityCollection<CustomerMarkUpEntity>();
        EntityCollection<CustomerMarkUpEntity> CustomerMarkUpCollectionToDelete = new EntityCollection<CustomerMarkUpEntity>()


        public void ShowCustomerMarkUp()
        {
            // get the markup collection and set the data source of the grid.
            CustomerMarkUpCollection =....
            ....

             CustomerMarkUpGrid.DataSource = CustomerMarkUpCollection;

        }

// delete record by rt clicking "delete row"

        private void deleteRecordsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (UltraGridRow row in CustomerMarkUpGrid.Selected.Rows)
            {
                CustomerMarkUpEntity SelectedCustomerMarkUp = CustomerMarkUpCollection[row.Index];
                CustomerMarkUpCollectionToDelete.Add(SelectedCustomerMarkUp);
            }
            DeleteCustomerMarkUp();

        }


        private void DeleteCustomerMarkUp()
        {
            DataAccessAdapter adapter = new DataAccessAdapter();
            foreach (CustomerMarkUpEntity cme in CustomerMarkUpCollectionToDelete)
            {
                CustomerMarkUpCollection.Remove(cme);
                adapter.DeleteEntity(cme);
            }
            adapter.Dispose();
        }


Again...its only a problem on the last eneity. Let me know if there is something that i am doing wrong. Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39926
Joined: 17-Aug-2003
# Posted on: 13-Apr-2007 16:27:02   

Don't use general chat for support calls, as this forum doesn't end up in our support queues. Moved to General

Frans Bouma | Lead developer LLBLGen Pro
Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Apr-2007 17:15:45   

Please run the application in debug mode, then break when you feel the system is gone into a hang state or better before it tries to delete the last entity, so you can know what's going on exactly. A better approach is to delete the entities from the database and then re-fetch the collection from the database rather than removing entities from the entity collection.

Also it would be more helpful if we know more details about your setup, refer to the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=7722

Posts: 254
Joined: 16-Nov-2006
# Posted on: 14-Apr-2007 22:29:35   

And if this is a production hang issue you can't simply debug with VS.NET use the techniques outlined in

http://msdn.microsoft.com/msdnmag/issues/05/07/Debugging

in the section "Managed Thread Executing Endlessly"

You would need to provide a hang dump so we can examine the state of the process.