Hi,
lately I've posted about es not retrieving the primary key value (default = NewID()) and so I ended up overriding the addnew() method in my custom base class. Some new problems have been discovered since then, when I load an entity (or collection) and then modifiy it and save it to the DB I get esConcurrencyExceptions:
Code:
EntitySpaces.Interfaces.esConcurrencyException was unhandled by user code
Message="Error in VistaDBProvider.esSaveDataTable"
Source="EntitySpaces.Core"
StackTrace:
at EntitySpaces.Core.esEntity.SaveToProvider(esSqlAccessType sqlAccessType)
at EntitySpaces.Core.esEntity.Save(esSqlAccessType sqlAccessType) at EntitySpaces.Core.esEntity.Save()
at BusinessObjects.MyEntity.MyMethod(BackgroundWorker Worker)
at MyRootNameSpace.MyProgressBarWindow.SomeBackgroundWorker_DoWork(Object sender, DoWorkEventArgs e)
in C:\Documents and Settings\SomeUser\My Documents\Visual Studio 2008\Projects\CurrentVersion\MySolution\SomeFolder\CommonForms\MyProgressBarWindow.vb:line 25
at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e) at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument)
InnerException: System.Data.DBConcurrencyException
Message="Concurrency violation: the UpdateCommand affected 0 of the expected 1 records."
RowCount=1
Source="System.Data"
StackTrace:
at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows)
at EntitySpaces.VistaDBProvider.DataProvider.SaveDynamic(esDataRequest request)
at EntitySpaces.VistaDBProvider.DataProvider.EntitySpaces.Interfaces.IDataProvider.esSaveDataTable(esDataRequest request)
InnerException:
As you can see this time the bug occurred with the code running in a backgroundworker, but it also happens when running in the UI thread.
Another thing is that my old code was running fine using transactions but now some transactions just won't commit. The pseudo code would look like this:
Code:
Dim accounts as new accountsCollection
Dim q as new accountsQuery("q")
'some other query object in order to build complex query
accounts.load(q)
Using scope as new esTransactionScope
For each account in accounts
Dim someentity as myEntity = account.SomeTablesByForeignKey.AddNew()
'give values to some fields
Dim someOtherEntity as myOtherEntity = someEntity.SomeOtherTablesByForeignKey.AddNew()
'give values to some fields
Dim aFunkyEntity as New FunkyEntity
'Do stuff to aFunkyEntity
aFunkyEntity.Save()
Next
'Save() or SaveAndDiscard() as I am not using the collection after saving
accounts.Save() 'some concurrencyException being thrown
scope.Complete()
End Using
This kind of bug (unexpected behavior) is really annoying because I'm in real a hurry, I mean I really didn't expect wasting all this time debugging, I had planned to move forward and implement a lot of new features asap (so did my clients). This is just some sample code but in fact It happens in a lot of places (However I've noticed this mostly happened when navigating through hierarchies).
I'd be more than grateful if you spent some time digging into this bug.
Regards,
Thanks!
- El pipo -