如何从分离在DataContext的跟踪机制LINQ到SQL数据对象? [英] How to detach a LINQ-to-SQL data object from the DataContext's tracking mechanism?

查看:117
本文介绍了如何从分离在DataContext的跟踪机制LINQ到SQL数据对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

询问后这个问题,在那里我得知如何使用表< T> .Attach()方法的工作,我还有一个问题。

After asking this question, where I was informed of how the Table<T>.Attach() method works, I have another question.

你如何分离从的DataContext 的状态跟踪机制LINQ到SQL数据对象?基本上,我想拉一个记录和更改的记录中的数据。但是,当我打电话的SubmitChanges()在同一个的DataContext 举例来说,我不希望记录,除非更新我已经明确要求附加()。这是如何实现的?

How do you detach a LINQ-to-SQL data object from the DataContext's state tracking mechanism? Basically, I want to pull a record and change the data on the record. But, when I call SubmitChanges() on the same DataContext instance, I do not want the record to be updated unless I have explicitly called Attach(). How is this accomplished?

推荐答案

从这个网站的解释如何拆LINQ对象此方法添加到要分离的对象:

From this site explaining how to detach a linq object add this method to the object you want to detach:

public void Detach()
{
    GetType().GetMethod("Initialize", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(this, null);
}

这篇关于如何从分离在DataContext的跟踪机制LINQ到SQL数据对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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