使用not in语句将更新查询转换为linq [英] convert update query to linq with not in statement
本文介绍了使用not in语句将更新查询转换为linq的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的sql语句是
update Gallery set IsPublished = 0 where GalleryId not in ('1','2');
如何将其转换为linq
how to convert this into linq
预先感谢
推荐答案
您不能在linq查询中进行UPDATE.您的SELECT查询可以是这样的:
You cannot UPDATE in a linq query. Your SELECT query can be something like:
List<int> ids = new List<int>() { 1, 2 }; // Assuming integers here
var galleriesToUpdate = context.Gallery
.Where(g => !ids.contains(g.GalleryId)).ToList();
然后更新它们
foreach(var gallery in galleriesToUpdate) {
gallery.IsPublished = 0;
}
然后使用上下文将其保存.
And then save them using the context.
context.SubmitChanges();
这篇关于使用not in语句将更新查询转换为linq的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文