如何拒绝 Linq to SQL 的 DataContext 中的所有更改? [英] How can I reject all changes in a Linq to SQL's DataContext?

查看:19
本文介绍了如何拒绝 Linq to SQL 的 DataContext 中的所有更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Linq to SQL 的 DataContext 上,我可以调用 SubmitChanges() 来提交所有更改.

On Linq to SQL's DataContext I am able to call SubmitChanges() to submit all changes.

我想要的是以某种方式拒绝数据上下文中的所有更改并回滚所有更改(最好不去数据库).

What I want is to somehow reject all changes in the datacontext and rollback all changes (preferable without going to the database).

这可能吗?

推荐答案

在 .net 3.0 中使用 db.GetChangeSet().Updates.Clear() 进行更新,db.GetChangeSet().Inserts.Clear() 用于新的或 db.GetChangeSet().Deletes.Clear() 用于已删除的项目.

In .net 3.0 use the db.GetChangeSet().Updates.Clear() for updated, db.GetChangeSet().Inserts.Clear() for new or db.GetChangeSet().Deletes.Clear() for deleted items.

在 .net 3.5 及更高版本中,GetChangeSet() 的结果现在是只读的,在 for 或 foreach 中循环集合并刷新每个 ChangeSet 表,就像 macias 在他的评论中写的一样.

In .net 3.5 and above the result of GetChangeSet() is now readonly, loop the collection in for or foreach and refresh every ChangeSet table like also macias wrote in his comment.

这篇关于如何拒绝 Linq to SQL 的 DataContext 中的所有更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆