tags:

views:

58

answers:

1

I have three tables related to each other. They represent a hierarchical object.

A_Table-> B_Table -> C_Table

I drilled my error down to setting the primary key values to their same values as before. When I SubmitChanges(), it fails after about 30 seconds with an error of:

"This SqlTransaction has completed; it is no longer usable."

I know that the primary key values are identical before and after. I am under the impression that Linq to SQL only modifies field values if they are not equivalent to the existing field values. The dataContext.Log during this code and the failure do not include SQL update statements.

Why would this fail? Is it really trying to do some sort of in-RAM cascading update?

+1  A: 

By default all Linq to Sql generated objects implement INotifyPropertyChanging which the DBContext will use for change tracking and in which case it will not detect setting an identical value.

Only in cases where the object doesn't implement INotifyPropertyChanging will the change tracking mechanism use a hidden copy of the object to detect changes during calls to SubmitChanges().

Take a look at Object States and Change-Tracking (LINQ to SQL) for an explanation of the change tracking.

--- Update: This actually isn't totally correct; here is an excerpt from a Linq to Sql class from the DBContext designer.cs file:

[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Tasks")]
public partial class Task : INotifyPropertyChanging, INotifyPropertyChanged
{
    private int _TaskId;

    [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_TaskId", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
    public int TaskId
    {
        get
        {
            return this._TaskId;
        }
        set
        {
            if ((this._TaskId != value))
            {
                this.OnTaskIdChanging(value);
                this.SendPropertyChanging();
                this._TaskId = value;
                this.SendPropertyChanged("TaskId");
                this.OnTaskIdChanged();
            }
        }
    }
}

Are your primary key values integers and does your code check the previous value like this?

joshperry