由网友(小熊迷路)分享简介:我正在使用LINQ to SQL来与我的数据库进行交互,我尝试做以下操作来更新数据库中的单个行:I am using LINQ to SQL to interact with my database and I am trying to do the following to update a single row...
我正在使用LINQ to SQL来与我的数据库进行交互,我尝试做以下操作来更新数据库中的单个行:
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 this update the database with the change I made to the row? or is there something I'm missing?
感谢您的帮助
推荐答案
几件事情要检查:
使用相同的code段的DataContext
,这意味着它不会削减,并从不同的方式粘贴在那里你实例化新的的DataContext
实例?
是 DataContext.ObjectTrackingEnabled
属性设置为真
?它应该是默认,但如果它的假
那么你的的DataContext
将无法进行更新。
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?
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.相关推荐
最新文章