Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用not in语句将update查询转换为linq_Sql_Linq - Fatal编程技术网

Sql 使用not in语句将update查询转换为linq

Sql 使用not in语句将update查询转换为linq,sql,linq,Sql,Linq,我的sql语句是 update Gallery set IsPublished = 0 where GalleryId not in ('1','2'); 如何将其转换为linq 提前感谢您无法在linq查询中更新。您的SELECT查询可以类似于: List<int> ids = new List<int>() { 1, 2 }; // Assuming integers here var galleriesToUpdate = context.Gallery

我的sql语句是

update Gallery set IsPublished = 0 where GalleryId not in ('1','2');
如何将其转换为linq


提前感谢

您无法在linq查询中更新。您的SELECT查询可以类似于:

List<int> ids = new List<int>() { 1, 2 }; // Assuming integers here
var galleriesToUpdate = context.Gallery
    .Where(g => !ids.contains(g.GalleryId)).ToList();
然后使用上下文保存它们

context.SubmitChanges();
context.SubmitChanges();