如何处理 ASP.NET 动态数据中的并发控制?

发布于 2024-09-04 04:57:57 字数 265 浏览 4 评论 0原文

动态数据以及建立和运行一个简单网站的简单快捷给我留下了深刻的印象。我计划将其用于一个简单的内部人力资源管理网站,用于注册人员的技能/学位/等。

我一直在 www.asp.net/dynamicdata 上观看介绍视频,他们从未提到的一件事是如何处理并发控制。

看来 DD 并没有立即处理它(除非有一些我没有看到的设置),因为我手动生成了更改冲突异常,并且应用程序失败了,没有任何用户友好的消息。

有谁知道DD是否可以开箱即用?或者您是否必须以某种方式将其构建到网站中?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

葬花如无物 2024-09-11 04:57:57

DD 不会立即处理并发性。

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

铁憨憨 2024-09-11 04:57:57

一种方法是在数据库端实现这一点,通过向每个表添加“上次更新”时间戳列(或其他唯一标记,例如 GUID)。

然后,您为每个表创建一个更新触发器。对于正在更新的每一行,传递的“上次更新”标记是否与数据库中该行上的标记相同?
如果是这样,请更新该行,但为其添加一个新的“上次更新”标记。
如果不是,请引发特定的“数据已过期”异常。

在客户端,对于更新的每一行,您需要刷新“上次更新”标记。

在客户端代码中,您监视“数据已过期”异常并向用户显示一条有用的消息,要求他们刷新数据并重新提交更改。

希望这有帮助。

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.

路弥 2024-09-11 04:57:57

一切都取决于定义,“开箱即用”是什么意思。当然,您必须创建大量代码来处理并发,但有些功能可以帮助我们实现它。

我最喜欢的模型是基于 SQL Server 的 rowversion 数据类型的“乐观并发”。它就像“上次更新”时间戳,但是您不需要为每个表使用任何更新触发器。每次更新表行中的数据时,SQL Server 都会自动对表中相应的“时间戳”列进行所有更新。我在旧答案Sql事务的并发处理中描述了它。我希望它对你有帮助。

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.

不及他 2024-09-11 04:57:57

我的印象是动态数据会更新底层数据源。也许您可以在 App_Init 部分注册的数据元模型上指定并发模型(悲观/乐观)。但你可能会遇到无法保存更改的错误,所以默认情况下会很悲观,最后会失败......

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

白云悠悠 2024-09-11 04:57:57

抱歉重播晚了。是的,DD在项目快速开发方面太强大了。不仅它是 .Net 4.0 的基础。 DD 得到了更多增强,已包含在.Net 4.0 中。

DD 主要工作在 Linq to sql 上。我建议你看看那部分。

在 linq to SQl 中,当您转到表的属性时,您会在那里找到一个属性,该属性指定 wheater 在更新新值之前检查旧值。如果你做到这一点,我想你的问题就会得到解决。

祝你好运。

让我们互相学习吧。

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.

说不完的你爱 2024-09-11 04:57:57

Binary Worrier 给出的解决方案有效,并且广泛用于提供 GUI 来合并更改的平台(例如源代码控制程序、wiki 引擎等)。这样,任何用户都不会丢失他们的更改。另一方面,它需要大量代码或使用外部组件或 DLL。

如果您对此不满意,另一种方法是锁定正在编辑的记录。在用户提交更改或其会话过期之前,其他人都无法编辑该记录。它有优点和缺点,但与第一个选项相比需要很少的代码。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文