tags:

views:

10

answers:

1

If I make changes to an existing linq object by assigning a "new" object of the same type (with different values), SubmitChanges does not make the changes in the database. why not?

  existing= new Data.Item{a=1, b=2...};

vs

  existing.a= 1;
  existing.b= 2;
A: 

Because you are not changing the object, you are assigning a new object to the variable.

You need to assign to fields one by one, (or InsertOnSubmit... but that will create a new object in the database and it does not sound like that is what you want to do).

This approach will sort of work if you we assigning the newly created object to a field of an object that LINQ to SQL knows about, but once again, that would be creating a new object rather than changing the one that field previously pointed to (which could result in a bunch of garbage rows in your database if you never get rid of them).

Aaron Maenpaa