LINQ to SQL的数据库行没有更新 [英] LINQ to SQL database row not updating

查看:176
本文介绍了LINQ to SQL的数据库行没有更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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?

感谢您的帮助

推荐答案

几件事情要检查:

  1. 使用相同的code段的DataContext ,这意味着它不会削减,并从不同的方式粘贴在那里你实例化新的的DataContext 实例?
  2. DataContext.ObjectTrackingEnabled 属性设置为?它应该是默认,但如果它的那么你的的DataContext 将无法进行更新。
  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.

这篇关于LINQ to SQL的数据库行没有更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆