0

This is for a RIA Services application:

We have an entity A that looks like:

ID   int (PK, identity)
Code string

The Code consists of a two character prefix AB, a second two character prefix CD then a four digit integer. When the entity is added to the database, the user should input ABCDas the code, and the application should append the smallest possible integer to the code, that has not already been used in another code with the AB prefix. For example, if the db looks like:

ABCD0001
ABCD0002
ABEF0003
CDEF0001

and the user inputs the prefixes ABGH, the code should be ABGH0004.

There will be multiple people using this application simultaneously so I don't think anything Cient-Side is a great option. Any thoughts?

Thanks!

nosirrahcd
  • 1,467
  • 3
  • 18
  • 36
  • this is really a SQL question, rather than a RIA services question. – Alastair Pitts Jul 24 '12 at 04:33
  • I strongly disagree. I am fully capable of doing this in SQL using a trigger. That doesn't play well with Ria though, so I am hoping there is a way to do it from the DomainService layer OR a good way to implement a trigger WITH Ria... – nosirrahcd Jul 24 '12 at 14:00

1 Answers1

0

I think your biggest problem if you try and do this inside of RIA Services or the client is concurrent users breaking the sequence with simultaneous commits.

My advice would be to use a DB trigger to compute this value in the database, this means that any simultaneous commits will get the correct computed code.

To refresh the client-side entity with the new code, as I don't believe it will be automagically updated after the commit, you'll need to load the entity into the client again using the LoadBehavior.RefreshCurrent to force it to update the property with the saved value.

It's pretty cumbersome, but there really isn't a good way to do this only client side.

Alastair Pitts
  • 19,423
  • 9
  • 68
  • 97