且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

强制LinqToSql提交

更新时间:2023-02-13 20:45:19

我还没有找到一种强制实体上的属性变脏的方法.从LinqToSql代码的挖掘来看,似乎是跟踪了旧值,然后将其与新值进行了比较,因此通常必须使用Attach或必须使用当前对象来创建新引用.

I haven't found a way to force property on entity to become dirty. from digging in LinqToSql code it appears that old value is tracked and then compared to the new value, so in general either Attach must be used or current object must be clonned to create new reference.

我通过自定义表类来解决XElement的问题.更改XElement时,我只是基于旧元素创建新的XElement:

I worked around my problem with XElement by customizing my table class. when XElement is changed, I simply create new XElement based on the old element:

partial class Table
{
    partial void OnLoaded()
    {
        if( XmlData != null )
        {
            XmlData.Changed += this.XmlData_Changed;
        }
    }

    private void XmlData_Changed( object sender, XObjectChangeEventArgs e )
    {
        this.ModifiedCardData = new XElement( this.XmlData );
    }
}