开发者

LINQ to SQL database row not updating

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 ro开发者_JAVA技巧ws).Single();
aRow.attribute = "something";

dataContext.SubmitChanges();

shouldn't this update the database with the change I made to the row? or is there something I'm missing?

thanks for any help


Another thing to check: ensure the table has a primary key.


A couple of things to check:

  1. Is your code snippet using the same DataContext, meaning it's not cut and pasted from different methods where you're instantiating new DataContext instances?
  2. Is your DataContext.ObjectTrackingEnabled property set to true? It should be by default, but if it's false then your DataContext won't be able to perform the update.


That code should work correctly, so it must be elsewhere in the code or in the database itself.

Have you checked to make sure that the column you are updating is not read-only? As pst mentioned, are you using transactions?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜