LINQ 未在 .SubmitChanges() 上更新 [英] LINQ not updating on .SubmitChanges()

查看:26
本文介绍了LINQ 未在 .SubmitChanges() 上更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么理由让这样的事情行不通吗?

Is there any reason something like this would not work?

这是我用 LINQ 更新表中记录时多次使用的逻辑:

This is the logic I have used many times to update a record in a table with LINQ:

 DataClasses1DataContext db = new DataClasses1DataContext();
 User updateUser = db.Users.Single(e => e.user == user);
 updateUser.InUse = !updateUser.InUse;
 db.Log = new System.IO.StreamWriter(@"c:	emplinq.log") { AutoFlush = true };
 db.SubmitChanges();

(updateUser.InUse 是一个位域)

(updateUser.InUse is a bit field)

由于某种原因它不起作用.当我检查 linq.log 时,它完全是空白的.

For some reason it isn't working. When I check the linq.log it is completely blank.

我的 .dbml 会不会有问题?其他表似乎工作正常,但我比较了 .dbml 中的属性,它们都匹配.

Could there be a problem with my .dbml? Other tables seem to work fine but I've compared properties in the .dbml and they all match.

就好像 db.SubmitChanges();未检测到任何需要的更新.

It's as if the db.SubmitChanges(); does not detect any updates being required.

推荐答案

该表无法正确更新,因为它没有主键.(实际上它有列,但是当我对我的开发表执行 SELECT INTO 时没有复制约束).DataContext 类需要更新的主键.

The table could not be updated properly because it had no primary key. (Actually it had the column but the constraint was not copied when I did a SELECT INTO my dev table). The DataContext class requires a primary key for updates.

这篇关于LINQ 未在 .SubmitChanges() 上更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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