none
Optimistic Concurrency in Entity Framework RRS feed

  • Question

  • Hi,


    I'm trying a way to recognize if another client has changed a record on the database while I have it open.
    Example:

    http://www.binaryintellect.net/articles/58216146-d464-42cb-b60d-15215467b107.aspx

    or

    http://www.codeproject.com/Tips/743507/Detecting-concurrency-issues-with-Entity-Framework

    So, I have a table sql server like this:
    IdProduct(int)
    Name(varchar)
    Price (decimal)
    Version(timestamp)

    I also have a .edmx file that reflects the database.
    So, I set Version's property (inside edmx diagram) ConcurrencyMode = fixed.

    Then, I opened my product on the windows form.

    Manually I changed product's price (changing timestamp) in database.

    Then click on savechanges() on winform, and it updated the record, although initial timestamp is changed...



    code in class is this:

                                                try
                                                {
                                                    _oc.SaveChanges();
                                                }
                                                catch (OptimisticConcurrencyException  ex)
                                                {
                                                    return false;
                                                }           }



    so, exception is never thrown!

    I'm forget something?

    thanks

    Saturday, July 4, 2015 6:22 PM

All replies

  • Hello,

    If you are looking to know if another client has changed data then look at SqlDependency class.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my webpage under my profile but do not reply to forum questions.

    Sunday, July 5, 2015 9:35 PM
    Moderator
  • Hi Kevininstructor,
    thanks for the answer, but it seems too expensive for what it must do.
    In the link I posted they are used "fixed" property.
    This is nice, but if I recreate again edmx file, I lose all settings.

    There should be something simpler. I do not think that I should create me two new applications to handle me the detection of optimistic concurrency.

    or maybe I'm wrong..

    thks

    Monday, July 6, 2015 8:43 AM
  • Hi duppino,

    Have your issue solved?

    If you still have question, you could share the whole project with us via OneDrive. We could reproduce the issue.

    Thursday, July 30, 2015 2:22 AM