Home > DeveloperSection > Forums > Update problems in Entity Framework
Goti Bandu

Total Post:119

Points:835
Posted on    September-28-2013 3:57 AM

 ADO.Net ADO.Net 
Ratings:


 1 Reply(s)
 998  View(s)
Rate this:

I want update my table with two conditions :

Type == "Employee" && Approved == false

and I use this code :

using (NoavaranModel.NoavaranEntities1 db=new NoavaranModel.NoavaranEntities1())
{
    var query = db.Students.Where(p => p.Type == " Employee" && p.Approved == false).Single();
    query.IsRecivedSMS = true;
    db.SaveChanges();
}

but it's not working. Just updates one recode in db. How can I update all rows with above conditions in Entity Framework?



Pravesh Singh
Pravesh Singh

Total Post:101

Points:709
Posted on    September-28-2013 6:33 AM

Hey Goti!

Just change the query to not select only one record which fits your contition, but all. Then update them all.

using (NoavaranModel.NoavaranEntities1 db=new NoavaranModel.NoavaranEntities1())
        {
            var query = db.Students.Where(p => p.Type == "پیش ثبت نام" && p.Approved == false);
            foreach(var record in query)
            {
              record.IsRecivedSMS = true;
            }
            db.SaveChanges();
        }

Don't want to miss updates? Please click the below button!

Follow MindStick