In order to update the database using SaveChanges() method, following are the ways to do this.
Option 1
- var ls=new int[]{2,3,4};
- var name="Foo";
- using (var db=new SomeDatabaseContext())
- {
- var some= db.SomeTable.Where(x=>ls.Contains(x.friendid)).ToList();
- some.ForEach(a=>
- {
- a.status=true;
- a.name=name;
- }
- );
- db.SubmitChanges();
- }
Option 2- using (var db=new SomeDatabaseContext())
- {
- db.SomeTable
- .Where(x=>ls.Contains(x.friendid))
- .ToList()
- .ForEach(a=>
- {
- a.status=true;
- a.name=name;
- }
- );
- db.SubmitChanges();
- }
Option 3- using (var db=new SomeDatabaseContext())
- {
- foreach (var some in db.SomeTable.Where(x=>ls.Contains(x.friendid)).ToList())
- {
- some.status=true;
- some.name=name;
- }
- db.SubmitChanges();
- }