Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to Handle Concurrency? #4651


User avatar
0
velu created

Hi,

how can we handle concurrency concerning database operations within the application safe and easily? We need to detect that two or more users are changing the same datasets and warn them.


3 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team
  • User Avatar
    0
    bbakermmc created

    Not sure why they referenced that previous forum post. This is very easy to do in EF.

    <a class="postlink" href="http://www.learnentityframeworkcore.com/configuration/data-annotation-attributes/concurrencycheck-attribute">http://www.learnentityframeworkcore.com ... -attribute</a>

    Add the [ConcurrencyCheck] attribute to the fields you want to be auto added to the where clause.

    So instead of update x set x.name = Person1 where x.id = 1 it would be update x set x.name = Person1 where where x.id = 1 and x.name = PersonA

  • User Avatar
    0
    aaron created
    Support Team

    No need for the hostility. I referenced that topic because it's directly related and it offers solutions to a few potential issues.

    Using the [ConcurrencyCheck] attribute means you cannot modify those values. A RowVersion property is the way to go.

    A better link would be: <a class="postlink" href="http://www.learnentityframeworkcore.com/concurrency">http://www.learnentityframeworkcore.com/concurrency</a>