Print Page | Close Window

Concurrency handling and EntitiesWithErrors is null

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=945
Printed Date: 27-Jan-2026 at 8:49pm


Topic: Concurrency handling and EntitiesWithErrors is null
Posted By: sebma
Subject: Concurrency handling and EntitiesWithErrors is null
Date Posted: 22-Sep-2008 at 2:20am
I followed the learning units on handling concurrency and having an AutoIncrement RowVersion columns and BaseEntity etc., and it works. A EntityManagerSaveException is now thrown when there is a concurrency conflict.

However, I do not know why the inner exception's EntitiesWithErrors is always null, as in the TODO codes below :-(

      public static ConflictScenario HandleConcurrencyException(DomainModelEntityManager pEntityManager, EntityManagerSaveException pException, ConcurrencyResolutionStyle pResolutionStyle)
      {

          StringBuilder msg = new StringBuilder();

          if (pResolutionStyle == ConcurrencyResolutionStyle.JustReportTheViolation)
          {
              Console.WriteLine("A concurrency error occurred while saving your data." + "\n" + "\n" + " Someone probably saved their changes while you were making your changes." + "\n" + "\n");
              return ConflictScenario.NotDiscriminated;
          }
          else
          {
          // TODO: pException.EntitiesWithErrors is null
          //    Entity entityWithError = pException.EntitiesWithErrors[0];
          //    switch (pResolutionStyle)
          //    {
          //        case ConcurrencyResolutionStyle.DatabaseVersionWins:
          //            return KeepDatabaseChanges(pEntityManager, entityWithError);
          //        case ConcurrencyResolutionStyle.LocalVersionWins:
          //            return KeepMyChanges(pEntityManager, entityWithError);
          //        case ConcurrencyResolutionStyle.ResolveConflicts:
          //            return ResolveMyConflicts(pEntityManager, entityWithError);
          //        default:
                      return ConflictScenario.NotDiscriminated;
          //    }
          }
      }


Thanks and best regards
-Sebastian



Replies:
Posted By: GregD
Date Posted: 23-Sep-2008 at 2:01pm
Looking into this...back soon.


Posted By: GregD
Date Posted: 24-Sep-2008 at 5:45pm
Sebastian:
 
Using the current release version of DevForce EF (4.2.0) and the concurrency tutorial from that, I am unable to reproduce your problem. My pException.EntitiesWithErrors[0] contains the entity involved in the conflict.
 
I notice that your code is a bit different from that in the concurrency learning unit that accompanies the 4.2.0 release. Where did it come from?
 
Greg Dunn
 


Posted By: sebma
Date Posted: 25-Sep-2008 at 8:32am
Hi Greg,

I zipped my associated files in attachment, not sure if they make any sense without the complete VS solution.

I was merely duplicating the codes from "Program Files\IdeaBlade DevForce EF\Learning Units\200 Intermediate\030 Handling Concurrency Conflicts\02 Code CSharp\Completed Solution".

Thanks
-Sebastian uploads/370/Concurrency_Files.zip - Concurrency_Files.zip


Posted By: GregD
Date Posted: 25-Sep-2008 at 2:58pm
Sebastian, I did the following:
 
1. Took your version of ConcurrencyHandler.cs and plopped it into the Completed Solution from the concurrency Learning Unit in the product release;
2. Changed the namespace back to "UI";
3. Compiled the app successfully;
4. Set a breakpoint just inside the HandleConcurrencyException() method;
5. Ran two copies of the app (one by double-clicking the UI.exe executable);
6. Opened the Employee tab in both instances of the app to load the Employee data;
7. Changed Nancy Davolio's first name in the instance run by double-clicking UI.exe, and saved the change;
8. Changed Nancy's first name in the instance launched from inside Visual Studio, and attempted to save that, resulting in a concurrency exception;
9. At the breakpoint in HandleConcurrencyException, examined pException.EntitiesWithErrors[0] and found Nancy Davolio there.
 
So, I am unable to reproduce the problem.
 
Can you do the steps above with the *unchanged* Completed Solution with the Learning Unit and tell me if you get a different result?
 
Thanks,
Greg
 


Posted By: sebma
Date Posted: 25-Sep-2008 at 11:42pm
Sure Greg, I shall do this over the weekend ;-)



Print Page | Close Window