你怎么在LinqToSql明确的变化? [英] How do you clear changes in LinqToSql?

查看:98
本文介绍了你怎么在LinqToSql明确的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框在一个数据绑定到我的对象的名单在我的视图模型我的WPF应用程序。当用户更改选定的对象,然后保存之前选择其他项目,我需要清除所做的更改。

I have a combobox in my WPF app that is databound to my list of objects in my View Model. When the user makes changes to the selected object and then selects another item before saving, I need to clear the changes made.

我想我可以使用dataContext.GetChangeSet() .Updates.Clear(),但由于某些原因,集合是只读的。

I thought I could use dataContext.GetChangeSet().Updates.Clear() but for some reason the collection is read-only.

我也试图用dataContext.Refresh但这并不工作,如对象不存在于数据库中,我创建它手动从一个SP。

I've also tried to use dataContext.Refresh but this doesn't work either as the object doesn't exist in the database, I created it manually from an SP.

请帮忙。谢谢。

推荐答案

您最好的选择可能是重新查询到一个单独的数据上下文。您的可以的使用 DeleteOnSubmit (反之亦然),否定(从更改集)插入,但我宁愿不要,我自己。

Your best bet is probably to re-query into a separate data-context. You can negate an insert (from the change-set) by using DeleteOnSubmit (and the reverse), but I'd rather not, myself.

这篇关于你怎么在LinqToSql明确的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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