本文介绍了HOWTO撤消变更在LINQtoSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的数据层类我创建了一个函数来手动刷新数据源。

in my data layer class I have created a function to manually refresh the data source.

Public Sub DiscardAllChanges()

    _Context.Refresh(RefreshMode.OverwriteCurrentValues)

End Sub

现在的问题是,上下文的变更在这之后还会继续跟踪插入,删除和更新的,我做调用previous手动操作的 InsertOnSubmit 的,等等。

The problem is that the context ChangeSet after this operation still trace the previous operation of Insertion, Deletion and Update that I made calling manually InsertOnSubmit, etc.

是否有可能也很清楚的变更以某种方式?或者,如果不是你能建议我另外一个解决方案吗?我必须创建在业务变更集层?

Is it possible to clear also the ChangeSet in some way? Or if not can you suggest me another solution? Do I have to create a ChangeSet layer in the Business?

推荐答案

来处理最简单的方法是治疗的DataContext 为你的工作单位。在单个的DataContext ,那么无论成功或失败后,处置执行原子组相关业务()它(理想情况下,通过使用),并把它扔掉。

The easiest way to handle this is to treat the DataContext as your unit of work. Perform an atomic set of related operations on a single DataContext, then after either success or failure, Dispose() it (ideally via using) and throw it away.

你开始下一组操作对新的的DataContext 。同样地,您可以重新查询数据。

Start you next set of operations on a new DataContext. Likewise, you can re-query for data.

在一个对象按对象的基础上,你可以使用 GetOriginalEntityState (上表),以获得原始值,但你需要重新申请一个活对象,这不处理删除/插入的情况。

On an object-by-object basis, you can use GetOriginalEntityState (on the table) to get the original values, but you'd need to re-apply to a "live" object, and this doesn't handle the delete/insert cases.

这篇关于HOWTO撤消变更在LINQtoSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:11