My sql statement is
update Gallery set IsPublished = 0 where GalleryId not in ('1','2');
how to convert this into linq
Thanks in advance
See Question&Answers more detail:osMy sql statement is
update Gallery set IsPublished = 0 where GalleryId not in ('1','2');
how to convert this into linq
Thanks in advance
See Question&Answers more detail:osYou 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();
And then update them
foreach(var gallery in galleriesToUpdate) {
gallery.IsPublished = 0;
}
And then save them using the context.
context.SubmitChanges();