views:

157

answers:

4

I've been quite impressed with dynamic data and how easy and quick it is to get a simple site up and running. I'm planning on using it for a simple internal HR admin site for registering people's skills/degrees/etc.

I've been watching the intro videos at www.asp.net/dynamicdata and one thing they never mention is how to handle concurrency control.

It seems that DD does not handle it right out of the box (unless there is some setting I haven't seen) as I manually generated a change conflict exception and the app failed without any user friendly message.

Anybody know if DD handles it out of the box? Or do you have to somehow build it into the site?

A: 

Concurrency is not handled out the of the box by DD.

porkeypop
A: 

One approach would be to implement this on the database side, by adding a "last updated" timestamp column (or other unique stamp, such as a GUID) to each table.

You then create an update trigger for each table. For each row being updated, is the "last updated" stamp passed in the same as the one on the row in the database? If so, update the row, but give it a new "last updated" stamp. If not, raise a specific "Data is out of date" exception.

On the client side, for each row you update, you'd need to refresh the "last updated" stamp.

In the client code you watch for the "Data is out of date" exception and display a helpful message to the user, asking them to refresh the data and re-submit their change.

Hope this helps.

Binary Worrier
Thanks for your answer Binary. How would you catch the "Data is out of date" exception in the client code in DD?
Andrew
To be honest I haven't a clue, I "assumed" the exception bubbled up though the layers. Write a trigger that throws an exception and see what happens.
Binary Worrier
Yeah, the exception bubbles up and then gets displayed to the user through a message box in all it's un-user friendly glory. I'm not sure how to handle that exception ones it gets there though and show a nicer message to the user.
Andrew
Dumb question, but did you try putting a `try{}catch{}` block around the call to update? Can you catch the exception there? Or add a general event handler at the application level?
Binary Worrier
Not dumb at all! In Dynamic Data, all the database CRUD queries are created for you. You create your models and DD automatically generates web pages to list, view, create, and modify records in every table. Hence, I never had to even write the call to update.
Andrew
A: 

All depends on the definition, what do you mean under "out of the box". Of cause you have to create a lot of code to handle concurrency, but some features help us to implement it.

My favorite model is "optimistic concurrency" based on rowversion datatype of SQL Server. It is like "last updated" timestamp, but you need not use any update trigger for each table. All updates of the corresponding "timestamp" column in your tables will be made automatically by SQL server at every update of data in the table row. I describes it in my old answer http://stackoverflow.com/questions/2658443/concurrency-handling/2663654#2663654. I hope it will be helpful for you.

Oleg
A: 

I was of the impression the Dynamic data does the update on the underlying data source. Maybe you can specify the concurrency model (pessimistic/optimistic) on the data meta model that gets registered on the App_Init section. But you would probably get unable to save changes error, so by default would be pessimistic, last in loses....

ggonsalv
Yeah, you get a ChangeConflictException which is shown to the user in all its glory. I was wondering how I can catch this exception and then show it to the user in a nicer way.
Andrew
IS it the ASP.Net Yello Screen of Death? Maybe you could catch the error in global.asax Error section. Could you post the error in the question
ggonsalv
That's a good suggestion! Just redirect them to another page...
Andrew