开发者

How to handle concurrency control in ASP.NET Dynamic Data?

开发者 https://www.devze.com 2023-01-02 02:49 出处:网络
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 s

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 kn开发者_JAVA技巧ow if DD handles it out of the box? Or do you have to somehow build it into the site?


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


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.


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 Concurrency handling of Sql transactrion. I hope it will be helpful for you.


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....


Sorry to replay late. Yes DD is too strong when it come to fast development of project. Not only that it is base for .Net 4.0. DD is more enhance and have been included in .Net 4.0.

DD mostly work on Linq to sql. I will suggest you to have a look on that part.

In linq to SQl when you go to property of table you will find a property there which specify wheater to check the old value before updating new value. If you set that true I think your proble will get handle.

wish you best luck.

Let's learn from each other.


The solution given by Binary Worrier works and it's widely used on platforms providing a GUI to merge the changes (e.g. source control programs, wiki engines, etc). That way none of the users lose their changes. In the other hand, it requires much code or using external components or DLLs.

If you are not happy with that, another approach is just to lock the record that is being edited. Nobody else will be able to edit that record until the user commit the changes or his session expires. It has pros and cons but requires little code compared with the first option.

0

精彩评论

暂无评论...
验证码 换一张
取 消