Asp.Net 动态数据在单个事务中更新/插入 2 个表
我当前正在使用 Asp.Net 动态数据和 Linq to Sql 来创建一个仅具有与其关联的 CRUD 操作的简单站点。
不幸的是,我根本无法更改数据库架构,并且遇到了一个无法优雅解决的问题。
该数据库有一个中央用户表和一个与访问权限相关的附加表,其中每个用户有 3 行,具有访问类型和位标志,指示他们是否具有权限,例如 UserId、访问类型、是否具有访问权限。
要求是在用户详细信息和信息中提供复选框。编辑屏幕以允许选择访问权限。
我看到的最大问题是如何实现插入/更新/删除操作以确保两个表在一个事务中都被更改。
到目前为止,我能看到的唯一解决方案是劫持插入/更新/删除事件并手动完成所有操作,但如果是这样的话,我可能最好在普通的 Asp.Net Web 表单中编写页面,而不是尝试使用动态数据。
有人对我可以做到的任何其他方式有任何想法吗?
I'm currenlty using Asp.Net Dynamic Data, with Linq to Sql, to create an simple site that only has CRUD actions associated with it.
Unfortunately I'm not able to change the database schema at all and have run into an issue which I'm having trouble resolving gracefully.
The database has a central users table and an additional table related to access rights where there are 3 rows per user with a access type and bit flag indicating if they have the right e.g. UserId, Access Type, Has Access.
The requirement is that checkboxes are provided in the users details & edit screen to allow selection of the access rights.
The biggest problem that I can see is how to implement insert/update/delete actions to ensure both tables are altered within the one transaction.
So far the only solution I can see is to hijack the insert/update/delete event and do it all manually but if thats the case I would probably be better off writing the pages in normal Asp.Net webforms rather than trying to use Dynamic Data.
Does anybody have any ideas of any other ways I could do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个不幸的数据库设计。你是对的,你必须拦截数据上下文的 SubmitChanges() 并在那里进行专门的更新。另一种选择是使用
数据库触发器。
This is an unfortunate database design. You are right, you must intercept the SubmitChanges() of your data context and do the specialized updating there. Another option would be to use
database triggers.