Linq2EF:使用 CheckBoxList/ID 值集的结果更新记录
假设我在页面上有一个反映表数据的 CheckBoxList。用户取消选中先前选中的项目,并选中未选中的项目。我想使用 LINQ2EF 更新数据库,以便剩余的记录与新提交的检查项目相匹配。
换句话说,当页面提交时,我会得到一个包含已检查 ID 的 String[]
。然后我需要将数据库更新为:
- 删除那里的记录,但是 现在没有 ID
- 添加不存在的记录,但是 现在已检查 ID
- 留下记录,并且 仍然单独检查。
使问题更加复杂的是,提交的 Id 位于字符串数组中,但数据对象的 Id 为 int。
Say I have a CheckBoxList on a page reflecting table data. A user unchecks previously checked items, and checks ones that were not checked. I want to update the database with LINQ2EF so that the records remaining match the newly submitted checked items.
In other words, when the page submits, I get a String[]
of checked IDs. I then need to update the database to:
- Delete records that were there, but
now don't have an ID - Add records that were not there, but
now have IDs checked - Leave records that were there, and
that are still checked, alone.
Compounding the problem, the submitted Ids are in an array of strings, but the data objects have Id as an int.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,你写代码。
Um, you write code.