-1

我的sql语句是

update Gallery set IsPublished = 0 where GalleryId not in ('1','2');

如何将其转换为 linq

提前致谢

4

1 回答 1

0

您不能在 linq 查询中进行更新。您的 SELECT 查询可能类似于:

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;
}

然后使用上下文保存它们。

context.SubmitChanges();
于 2012-08-17T10:17:54.043 回答