LINQ不更新.SubmitChanges() [英] LINQ not updating on .SubmitChanges()

查看:78
本文介绍了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:\temp\linq.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.

推荐答案

该表没有主键,因此无法正确更新. (实际上,它具有该列,但是当我对我的dev表执行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天全站免登陆