There are some ways to update, I got the code below of that answer:
var ls=new int[]{2,3,4};
using (var db=new SomeDatabaseContext())
{
var some= db.SomeTable.Where(x=>ls.Contains(x.friendid)).ToList();
some.ForEach(a=>a.status=true);
db.SubmitChanges();
}
using (var db=new SomeDatabaseContext())
{
db.SomeTable
.Where(x=>ls.Contains(x.friendid))
.ToList()
.ForEach(a=>a.status=true);
db.SubmitChanges();
}
using (var db=new SomeDatabaseContext())
{
foreach (var some in db.SomeTable.Where(x=>ls.Contains(x.friendid)).ToList())
{
some.status=true;
}
db.SubmitChanges();
}
I put more for you to see that there are several ways to do it. The fact is that none of them will update with where id > 30
The .ForEach()
nothing more than a for each done in the result. The only advantage is that it gets cleaner using it.
I particularly when I need to do a simple update on several records I use a same database procedure. It all depends on your infrastructure, BD capacity and application server.
UPDATING
Regarding an official position of Microsoft on this I do not know if it exists. Until mid-last year (if memory serves me correctly) I looked for something and found nothing.
You can try some third party design to do this:
Entity Framework Extended Library
Entity Framework Extensions (Multiple Entity updates)
When there is a solution for this native EF probably these projects will even announce.
In the
.SaveChanges()
it will perform several updates. EF does not support batch update no. I will try to find a text I have read about it and put here if I can.– Ricardo