类型化数据集中的事务
拥有一个包含多个相关表的类型化数据集,以及这些表之间定义的关系。当我处理数据源时,我会添加、修改和删除记录,然后对每个表调用更新。
Requests Reapprovals UserRole
RequestId ----- RequestId ----- RoleId
Reason RoleId ----/ UserId
使用类型化数据集的原因是我必须检查现有数据以确定是否要添加、修改或删除记录...所以我需要完整转储我正在使用的所有内容(替代方案是 10,000当我一一处理记录时对数据库进行查询)。
我想要事务支持,但我没有找到使用类型化数据集来实现此目的的方法。例如,当我创建新的重新批准时,我正在创建新的请求。但如果重新批准更新失败,我不想保留该请求。
将更新调用放在 TransactionScope
下意味着如果任何记录失败,它们都会失败。不是我想要的。
如何提交或回滚类型化数据集中的相关行?
Have a typed dataset with several related tables, and relations defined between those tables. As I process a datafeed, I'm adding, modifying, and removing records, then calling update on each table.
Requests Reapprovals UserRole
RequestId ----- RequestId ----- RoleId
Reason RoleId ----/ UserId
The reason for using a typed dataset is that I have to check existing data to determine whether I'm adding, modifying, or removing records... so I need the full dump of everything I'm working with (the alternative would be 10,000 queries against the database as I process the records one by one).
I want transactional support, but I'm not seeing a way to do it with typed datasets. For example, I'm creating a new request when I create a new reapproval. But if the reapproval fails to update, I don't want to keep the request.
Putting the update calls under a TransactionScope
would mean that if any record fails, they all fail. Not what I want.
How would I commit or roll back related rows in a typed dataset?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用常规事务,也可以从 TableAdapterManager 实现类似事务的功能,如下例所示。
第一种方法是使用常规事务,
第二种方法是使用表适配器管理器。
使用此选项,您可以为要保存的表组创建 TAManager。就像你想让一组人得救,而另一组人失败一样。
You can use regular transactions and also achieve transaction like feature from TableAdapterManager as like in below examples.
First Approach to use regular transaction,
Second..with table adapter manager..
With this option you can create TAManagers for group of tables to save. like if you want one group to save and even if another get fail.
您可以使用具有不同范围选项的事务范围
You can use transaction scope with different scope options