Hi everyone,
I'm currently migrating a DAL from LLBL v1.x to v3.1. I already dealt with a lot of stuff, however some issues remain...
The most important one for now is the ORMConcurrencyException. Each user of my app has his own sql server (2005 or 2008, mostly 2008 for now). Sometimes, the users export and import larger parts of data using xml files.
During import, some entities have to be merged. One of them is PlayerEntity. Each player is defined by a GUID PlayerId (this is the primary key), and also has an ExternalId (string), which is used to identify players externally. When importing players, the app searches the local database for a player with the same PlayerId. If no such player is found, another search is performed, this time looking for an ExternalId of the imported player. If one is found, the app was using ForcedCurrentValueWrite in order to change the imported player's PlayerId to the existing player's PlayerId. This part of code looks like this:
PlayerEntity playerExisting = new PlayerEntity(player.PlayerId);
player.IsNew = !adapter.FetchEntity(playerExisting);
if (player.IsNew)
{
PlayerEntity dupPlayer = GetPossibleDuplicatePlayer(player, adapter);
if (dupPlayer != null)
{
Guid externalGuid = player.PlayerId;
player.Fields["PlayerId"].ForcedCurrentValueWrite(dupPlayer.PlayerId);
player.Fields["PlayerId"].IsChanged = true;
//player.Fields["PlayerId"].AcceptChange();
player.IsNew = false;
}
}
adapter.SaveEntity(player, true);
This used to work on LLBL v1.x that the project was using, with the AcceptChange line uncommented. I'm not sure what was this line for to be honest - it wasn't written by me. However... now, the SaveEntity fails with ORMConcurrencyException. More details:
Message: "During a save action an entity's update action failed. The entity which failed is enclosed."
Stack trace:
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PersistQueue(List`1 queueToPersist, Boolean insertActions, Int32& totalAmountSaved)
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, IPredicateExpression updateRestriction, Boolean recurse)
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave)
at EDH.Tennis.IO.Helpers.ImportHelper.ImportPlayer(XmlTextReader reader, DataAccessAdapter adapter) in C:\Users\Marcin\Desktop\KOD\tennismanager\trunk\EDH.Tennis.IO\Helpers\ImportHelper.cs:line 890
Of course I made sure, that a dupPlayer entity exists in the database when saving, there's no other thread modifying it or anything... Any ideas?
Marcin