When I save changes, I get the error:
A first chance exception of type 'IdeaBlade.Persistence.PersistenceManagerSaveException' occurred in IdeaBlade.Persistence.dll
Additional information: Save failed - Collection was modified; enumeration operation may not execute.
All I have to do to get the error (Example: Create a new Order, Create a new OrderDetail, Then add the Order to the CustomerOrders collection.)
Order.Create(persMgr)
OrderDetail.Create(persMgr, mOrder)
mOrderBS.MoveLast()
currentOrder = CType(OrderBS.Current, Order)
mCustomerOrder = CType(CustomerOrderBS.Current, CustomerOrder)
mCustomerOrder.Order = currentOrder
Dim pMgrSave As SaveHelper = New SaveHelper(pm)
Try
If pMgrSave.SaveAll Then
DevExpress.XtraEditors.XtraMessageBox.Show("Information Saved", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
DevExpress.XtraEditors.XtraMessageBox.Show("Nothing to Save", "No changes", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
DevExpress.XtraEditors.XtraMessageBox.Show("An exception of type " & ex.GetType().ToString() & _
" was encountered. ")
End Try
This is my save function:
Public Class SaveHelper
Private pMgr As PersistenceManager
Public Sub New(ByVal persMgr As PersistenceManager)
pMgr = persMgr
End Sub
Public Function SaveAll() As Boolean
Dim result As SaveResult
If pMgr.HasChanges Then
Try
result = pMgr.SaveChanges()
If result.Ok Then
Return True
End If
Catch ex As Exception
DevExpress.XtraEditors.XtraMessageBox.Show("An exception of type " & ex.GetType().ToString() & _
" was encountered. ")
End Try
End If
Return False
End Function
If I retry the save, it will save the tempId to the record and save it to the database. This only happens if I create a new Order
Yes, I would like an example to modify the persistence order.