如何将表单数据绑定到对象并在回发时丢失其值
我使用 ADO.NET 实体框架,我有一个页面数据绑定到代码文件中的实体变量。
该项目的层次结构是 Person.Orders 我希望用户向此 Person 实体添加/删除订单 (Person.Orders.Add(order)), 问题是,虽然实体尚未保存,但一旦用户回发,变量就会被处理,人员及其所有订单都会消失。 将实体/变量(复杂的)保存在缓存/内存/状态或其他什么中(不保存在商店中,我想仅当用户单击常规接受更改按钮时才将项目保存在商店中)应该是一个好的做法我想在空中建立层次结构)?
如果我不够清楚,我明天会提供更多细节,请接受我的道歉。
I use ADO.NET Entity-Framework, I have a page that is data-bound to an entity variable in the code file.
The hierarchy of the item is Person.Orders
I want the user to add/remove orders to this Person entity (Person.Orders.Add(order)),
The problem is that while the entity is not saved yet, once the user makes a post back, the variables are disposed and the person and all its orders are gone.
What should be a good practice on saving entities/variables (complex ones) in cache/memory/state or whatever (not save in the store, i want to save items in the store only when the user clicks the general Accept Changes btn, meanwhile i wanna build the hierarchy on the air)?
If I am not clear enough I will provide more details tomorrow, please accept my apology.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您期望在客户端上执行多个操作并在每次视图重新加载时加载实体时,使用会话状态来保留对象层次结构。 这样,您将反映用户更改,并将它们保留在内存中,直到触发最终操作,此时您可能会保存整个实体层次结构。
但请注意,如果您使用 inproc 会话,则应用程序域会在用户工作过程中被卸载。
Use session state to keep your object hierarchy while you expect several action on the client and load your entities on each view reload. This way you'll reflect user changes and you'll keep them in memory 'till the final action is triggered at which point you'll probably save the entire entity hierarchy.
But be aware of the appdomain being unloaded in the middle of your user's job if you're using inproc session.