Order of Handling DeletedItems during Save and DeepSave of Collections - Support - .netTiers - CodeSmith Community
Welcome to the CodeSmith Community!

Order of Handling DeletedItems during Save and DeepSave of Collections

.netTiers

A description has not yet been added to this group.

Order of Handling DeletedItems during Save and DeepSave of Collections

  • rated by 0 users
  • This post has 1 Reply |
  • 2 Followers
  • I ran into a problem when saving collections.  This problem occured due to deleting items from a TList and then adding a new item to the TList with the same primary key.  During the saving of this collection, it attempts to do the saves prior to the delete.  The inserted entity has a state of Added so it attempts to do an insert which fails with a primary key constraint error.

    The code that is executing is as follows:
            public void Save(TransactionManager transactionManager, <%=collectionClassName%> entityCollection)
            {
                foreach (<%=className%> entity in entityCollection)
                {
                    Save(transactionManager, entity);
                }
               
                foreach (<%=className%> entity in entityCollection.DeletedItems)
                {
                    Delete(transactionManager, entity);
                }
               
                // Clear the items to delete list.
                entityCollection.DeletedItems.Clear();
            }

    Is there a reason the DeletedItems are not handled first?  This would alleviate the problem I am having.  My current solution is either to change the templates or to use a workflow to Delete all of the children and then insert them all.
  • I just came across the same problem, but I have a unique index of a bunch of fields thats causing the error. It makes sense to process deletes first.

Page 1 of 1 (2 items)