locked
Resolving optimistic concurrency exceptions RRS feed

  • Question

  • User828542847 posted

    see the code

    using (var context = new BloggingContext()) 
    { 
        var blog = context.Blogs.Find(1); 
        blog.Name = "The New ADO.NET Blog"; 
     
        bool saveFailed; 
        do 
        { 
            saveFailed = false; 
            try 
            { 
                context.SaveChanges(); 
            } 
            catch (DbUpdateConcurrencyException ex) 
            { 
                saveFailed = true; 
     
                var entry = ex.Entries.Single(); 
                entry.OriginalValues.SetValues(entry.GetDatabaseValues()); 
            } 
     
        } while (saveFailed); 
    }

    tell me what these line of code is doing ?

                var entry = ex.Entries.Single(); 
                entry.OriginalValues.SetValues(entry.GetDatabaseValues()); 

    Tuesday, July 18, 2017 2:05 PM

Answers

All replies