具有自我跟踪实体的 ASP.NET GridView
我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,因为传递给更新方法的对象不是从数据库查询的,而是实例化的。您可以做的是将实体附加到上下文。这将解决这个问题。
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.
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.