LINQ to SQL database row not updated

I am using LINQ to SQL to interact with my database, and I am trying to do the following to update a single row in the database:

DataClassesDataContext dataContext = new DataClassesDataContext();

TableName aRow = (from rows in dataContext.TableNames where rows.x == y select rows).Single();
aRow.attribute = "something";

dataContext.SubmitChanges();

shouldn't the database be updated with the change I made in the row? or is something missing?

thanks for any help

+3
source share
3 answers

A few things to check:

  • Is your code snippet using the same DataContext, which means that it is not cut and pasted from different methods where you instantiate DataContext?
  • Is the property DataContext.ObjectTrackingEnabledset to true? It should be the default, but if it is false, then yours DataContextwill not be able to perform the update.
+1

, : , .

+3

, - .

Have you verified that the updated column is not read-only? As mentioned in pst, are you using transactions?

0
source

All Articles