Concurrency

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
damon.cognito
Posts: 50
Joined: Wed 22 Jul 2009 09:30

Concurrency

Post by damon.cognito » Tue 23 Jun 2015 22:48

Our database is a large multi-user thing so we basically want to set Currency to fixed on every field. Is there a way to do this when creating the model other than writing a script to go through the model and making changes?

Secondly, the currency is at the record level, is there any support for it at the field level? For example, take

Table1 (id, field1, field2, field3)
(1, 1, 1, 1)
(2, 2, 2, 2)

If we load the first record (1, 1, 1) and only change field2 to 2 I want the sql to be produced to be:

Code: Select all

update Table1 set field2 = 2 where id = 1 and field2 = 1
not

Code: Select all

update Table1 set field2 = 2 where id = 1 and field1 = 1 and field2 = 1 and field3 = 1
i.e. it is valid for other fields to have been changed, just not the ones I have changed.

Shalex
Site Admin
Posts: 8241
Joined: Thu 14 Aug 2008 12:44

Re: Concurrency

Post by Shalex » Wed 24 Jun 2015 14:41

damon.cognito wrote:Our database is a large multi-user thing so we basically want to set Currency to fixed on every field. Is there a way to do this when creating the model other than writing a script to go through the model and making changes?
You are working with the Entity Framework model via Entity Developer, aren't you? Please select all necessary class properties in Model Explorer and set "Concurrency Mode=Fixed" for all of them at once.
damon.cognito wrote:Secondly, the currency is at the record level, is there any support for it at the field level? For example, take

Table1 (id, field1, field2, field3)
(1, 1, 1, 1)
(2, 2, 2, 2)

If we load the first record (1, 1, 1) and only change field2 to 2 I want the sql to be produced to be:

Code: Select all

update Table1 set field2 = 2 where id = 1 and field2 = 1
not

Code: Select all

update Table1 set field2 = 2 where id = 1 and field1 = 1 and field2 = 1 and field3 = 1
i.e. it is valid for other fields to have been changed, just not the ones I have changed.
The expression tree for the WHERE clause is constructed in EF engine, then it is passed to our EF provider for generating database specific SQL. Please address this suggestion (expression tree optimization) to Microsoft EF developers.

JIC
There is another approach to implement concurrency processing. Create a timestamp column in your table and refresh its value each time the record is updated. The timestamp column can be refreshed in two alternative ways
* at database side via trigger: http://postgresql.nabble.com/Re-timesta ... 46935.html
* at EF code side: iterate through all tracked changes and update the timestamp properties of all changed records in all entities in the SavingChanges event handler

damon.cognito
Posts: 50
Joined: Wed 22 Jul 2009 09:30

Re: Concurrency

Post by damon.cognito » Wed 24 Jun 2015 17:36

Shalex wrote:You are working with the Entity Framework model via Entity Developer, aren't you? Please select all necessary class properties in Model Explorer and set "Concurrency Mode=Fixed" for all of them at once.
Yes I am, but I just need to check what you are suggesting... are you suggesting expanding each of the 300+ class nodes, then selecting each individual field in each node?
Shalex wrote:
damon.cognito wrote:Secondly, the currency is at the record level, is there any support for it at the field level? ...
The expression tree for the WHERE clause is constructed in EF engine, then it is passed to our EF provider for generating database specific SQL. Please address this suggestion (expression tree optimization) to Microsoft EF developers.

JICx
There is another approach to implement concurrency processing. Create a timestamp column in your table and refresh its value each time the record is updated.
Thanks for the suggestion but that row level again, not field level; if I'm just updating field2 I don't care if field1 has changed (and visa versa). But if that is controlled by MS then I guess there is not much hope!

Shalex
Site Admin
Posts: 8241
Joined: Thu 14 Aug 2008 12:44

Re: Concurrency

Post by Shalex » Thu 25 Jun 2015 12:51

damon.cognito wrote:want to set Currency to fixed on every field. Is there a way to do this when creating the model [...]?
There is no way at the moment. Please submit your suggestion at http://devart.uservoice.com/forums/3867 ... -developer.
damon.cognito wrote:are you suggesting expanding each of the 300+ class nodes, then selecting each individual field in each node?
Open the *.edml model, navigate to Tools > Entity Developer > Model Explorer, press Ctrl+F to open the Find window:
Find what: .*
Look in: Properties
Use regular expressions: Checked
Now press Select All which will mark all properties.

damon.cognito
Posts: 50
Joined: Wed 22 Jul 2009 09:30

Re: Concurrency

Post by damon.cognito » Thu 25 Jun 2015 13:39

I tried your suggestion which is quite neat except it took over 10 minutes to 'select all' and another couple of minutes once I changed the setting (and this is not a slow machine). So I'll stick to an external script for now and post the suggestion at the link you provided. Thanks for your help.

cheers!

Shalex
Site Admin
Posts: 8241
Joined: Thu 14 Aug 2008 12:44

Re: Concurrency

Post by Shalex » Fri 26 Jun 2015 12:05

damon.cognito wrote:I tried your suggestion which is quite neat except it took over 10 minutes to 'select all' and another couple of minutes once I changed the setting (and this is not a slow machine).
We will investigate the issue and notify you about the result.

Shalex
Site Admin
Posts: 8241
Joined: Thu 14 Aug 2008 12:44

Re: Concurrency

Post by Shalex » Thu 16 Jul 2015 14:26

damon.cognito wrote:I tried your suggestion which is quite neat except it took over 10 minutes to 'select all' and another couple of minutes once I changed the setting (and this is not a slow machine).
The bug with freezing Visual Studio when using the Find dialog in large models is fixed in the new (5.7.654) build of Entity Developer: http://forums.devart.com/viewtopic.php?f=32&t=32134.

Post Reply