具有自我跟踪实体的 ASP.NET GridView

发布于 2024-11-19 18:29:22 字数 137 浏览 12 评论 0原文

我的 STE 工作得很好,可以通过 Web 表单上的各个控件(如文本框、备忘录等)跟踪更改,但与 asp.net gridview 一起使用时除外。当 Gridview 更新时,它总是显示“已添加”作为 STE 的状态。

有人能解决我的问题吗?

My STEs work very well and track changes with individual controls like textboxes, memo etc. on the webform, except when used with asp.net gridview. With Gridview on Update it says allways "Added" as state of the STE.

Has anyone a Solution for my Problem?

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

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

发布评论

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

评论(2

谈下烟灰 2024-11-26 18:29:22

是的,因为传递给更新方法的对象不是从数据库查询的,而是实例化的。您可以做的是将实体附加到上下文。这将解决这个问题。

HTH。

Yes because the object being passed to the update method is not queried from the DB, but instantiated. What you can do is attach the entity to the context. This will resolve this issue.

HTH.

伏妖词 2024-11-26 18:29:22

GridView 或 ObjectDataSource 都不会在请求之间保留实体。当您在 GridView 上触发数据修改事件时,将为您创建一个新的对象实例。它与您用于填充网格的实体不同 - 这些实例会丢失。

顺便提一句。在 Web 应用程序中使用 STE 并在请求中存储实体可能是我能想象到的最糟糕的用法。每个人都在试图减少 Web 应用程序中的内存占用以及客户端和服务器之间传输的数据量,而您的方向恰恰相反。

Neither GridView or ObjectDataSource persists entities among requests. When you trigger data modification event on the GridView a new instance of object is created for you. It is not the same entity you used to fill the grid - those instances are lost.

Btw. using STEs in web application and storing entities among requests is probably the worst usage I can ever imagine. Everybody is trying to reduce their memory footprint in web app as well as amount of transferred data between client and server and you are going exactly opposite direction.

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