Fetching different values in LINQ Concurrency conflict

If you have not read my post Resolving Concurrency conflicts in LINQ then I strongly recommend you to read that. This post is a simple added extension of said post.

After reading resolving concurrency conflict in LINQ you are pretty much aware of resolving mechanism of concurrency conflicts. Now assume a requirement that you need to print or fetch

  1. Current value of object
  2. Original value of object on context
  3. Current data base value.

This is very much possible by

  1. Enumerating over MemberConflicts of ChangeConflict object.
  2. Fetching MemberChangeConflict in object of MemberConflict


In child Foreach loop you can fetch values as ,


Catch statement should be modified as below to fetch and print different values.


For reference you can find full source code below,

using System;
using System.Linq;
using System.Data.Linq;

namespace Concurrency
    class Program
        static void Main(string[] args)

            DataClasses1DataContext context = new DataClasses1DataContext();

            #region without handling Conflict
            //Person personToUpdate = (from r in context.Persons
            //                         where r.PersonID == 1
            //                         select r).FirstOrDefault();
            //personToUpdate.FirstName = "John Papa";


            #region hanlding conflict

                Person personToUpdateConflict = (from r in context.Persons
                                                 where r.PersonID == 1
                                                 select r).FirstOrDefault();
                personToUpdateConflict.FirstName = "John";

            catch (ChangeConflictException c)
                foreach (ObjectChangeConflict o in context.ChangeConflicts)

                    foreach (MemberChangeConflict c1 in o.MemberConflicts)
                        var currentValue = c1.CurrentValue;
                        var originalValue = c1.OriginalValue;
                        var dataBaseValue = c1.DatabaseValue;

                        Console.WriteLine("Current Value of Object " + c1.CurrentValue);
                        Console.WriteLine("Original value in context " + c1.OriginalValue);
                        Console.WriteLine("Database value " + c1.DatabaseValue);




On running application, you should get output as below.


I hope this post was useful. Thanks for reading Smile

Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine

One response to “Fetching different values in LINQ Concurrency conflict”

  1. […] Fetching different values in LINQ Concurrency conflict […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com