LINQ to SQL context.GetChanges

I have two tables in a LINQ to SQL dbml file. I am trying to get all the changes presented in the context that I can get using

var myOtherContext;
var changes = context.GetChangeSet();

foreach (var change in changes)
{         
    Type t = change.GetType();
    if (change is Product )
    {
        myOtherContext.GetTable<Product>().InsertOnSubmit((Product) change);
    }
    if (change is Supplier)
    {
        myOtherContext.GetTable<Supplier>().InsertOnSubmit((Supplier)change);
    }
}

      

Basically, I copy all the changes that happened in one context to another context (myOtherContext). I don't want to use an if statement to check the type of change. Is there a way to write:

myOtherContext.GetTable<typeof(change)>().InsertOnSubmit((typeof(change) change);

      

Your help would be appreciated.

Regards, Parminder

+2


source to share


1 answer


How to use the custom version:



foreach (var change in changes.Inserts) // note inserts
{         
    myOtherContext.GetTable(change.GetType()).InsertOnSubmit(change);
}

      

+2


source







All Articles