This is a migrated thread and some comments may be shown as answers.

[Solved] lock table row between read and save

1 Answer 137 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
AndreaT
Top achievements
Rank 1
AndreaT asked on 28 Oct 2010, 08:26 AM
Hi,

in a web app I have an object with a filed that must be incremented with delta values. In order to do this I have to read the object from DB, apply delta increment to the same field and save the new value (example read 10, apply delta of 5, finally write 15). Between read and save operation it must be granted that no read and write occurs to that object.

which is the best way to do that?

thanks

b.r.
/@/

1 Answer, 1 is accepted

Sort by
0
Serge
Telerik team
answered on 02 Nov 2010, 08:28 PM
Hello AndreaT,

 Yes, there is a way to achieve this, you will have to modify the concurrency control so that you use pessimistic one. This means that a check is performed if the object is locked when selecting it. You can achieve this through two ways, however both of them are not yet exposed in the new designer/context API. You can expose them yourself by creating a partial class to your generated context and exposing the inner scope that is marked as protected. The code would look like this:

public partial class YourContextNameHere
{
    public IObjectScope Scope
    {
        get
        {
            return this.GetScope();
        }
    }
}

You can have a look at how to set the concurrency control mode at the bottom of this help article

I hope this is helpful, however if you need something else or it is unclear please let us know.

Sincerely yours,
Serge
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
AndreaT
Top achievements
Rank 1
Answers by
Serge
Telerik team
Share this question
or