使用LINQ to SQL执行更新/设置 [英] Using LINQ to SQL to perform an update/set

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

问题描述

因此,如果我直接使用此查询或使用db.ExecuteCommand(),一切都会正常;

So, if I use this query directly or by using db.ExecuteCommand() , everything will work fine;

update Market..Area set EndDate = NULL where ID = 666 and NID =1 and Code = 36003

但是,我似乎无法在LINQ to SQL中做到这一点,我尝试了几种似乎都应该起作用的不同方法,这是其中一个示例:

However, I cant seem to do this in LINQ to SQL, I've tried a few different methods that all seem like they should work, here is an example of one:

var s= db.Area.Single(s => s.ID == 666 && s.Code == 36003 && s.NID == 1);
s.EndDate = null;
db.SubmitChanges();

我不知道还有什么方法可以使它正常工作.

I dont know what else to try to get this working.

编辑

我只想编辑一个项目

推荐答案

在Area表上是否定义了主键? 如果未定义主键,Linq 2 SQL将不会对表进行更新. (据我所知,它将无声地失败).

Is there a primary key defined on the Area table? Linq 2 SQL will not make an update to a table without a primary key defined. (And, as far as I can remember, it will fail silently).

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

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