I am using RIA Services with Entity Framework in Silverlight 5. i have a following Foo
table;
Fooid
FooName
FooCode
FooRef
Fooid
is an auto-increment number - works like a charm on save ...
FooName
is set in ViewModel - works fine on save ...
FooCode
is a 3 letter code e.g. GRN, SIP, XYZ ... this is also set in the ViewModel .. no problem
FooRef
is an incrementing integer. e.g. last saved value on server is 100, now the next save should be 101.
i am a bit confused as how to get this latest number. i researched a bit and i found out two ways but i am confused using these and needs help how to implement.
First Method
from ViewModel, i can call an INVOKE from RIA Service, which can provide me the last saved FooRef
int. i can add it by 1 and pass the value on SubmitChanges.
Problem with First Method :
The problem i face with this method is, lets say there are 3 users at their workstations at different locations. they all start creating a new Foo
, when they call invoke method, they all will be given the same value which kind of breaks the whole concept down.
Second Method
I somehow intercept the Add method on server, may be via Repository, and get the value of FooRef
just before Adding this entity and submitting changes.
Onyone can help?