This post is somewhat related to this post of mine: How to synchronize database access in a WCF Service?
The responses I got there were over-complicated and \ or contradicting ... :(
I have created a sample WCF service, and I run 3 instances of clients against it. The service communicates with an SQL table called names, with several rows.
One client spawns function 1 in the service.
The second client spawns function 2 in the service.
function1 spawns a function on the service that :
a. Changes a specific row from 'Charlie' to 'Chin'
b. waits 5 seconds
c. changes the row again from 'Chin' to 'Carol'
function2 spawns a function that returns a list of all the names.
It is important to note that both functions in the service are wrapped with 'TransactionScope'.
What I do: I run function1 (which changes 'Charlie' to 'Chin' and waits for 5 seconds), then immediatly I spawn function2 which tries to get the list of names but hangs (because function1 hasn't finished yet), and after couple of seconds function1 changes the name from 'Chin' to 'Carol' and only then function2 is released and it returns the list of names.
The things is - the list of names that is returned from function2 doesn't contain 'Carol' ! it contains 'Charlie' ! Why is this ? I thought that because function2 hanged until function1 finished - it would also fetch the data only when function1 finished, but apparently this is not the case.
What am I doing wrong ?
I do not want to start using locks, because this would slow the whole system down. I will have approximately 20 methods in my final service, and I don't want all of them to have to use locks... (only 3-4 methods are for 'reading', but they are the ones that will be used 95% of the time)...