Menu ▼



Posted By :
avatarDotnet Learner
Total Views : 6779

Update multiple records in entity framework in a single line by using LINQ query

This example shows you how to update multiple records in database table that satisfies given condition (where condition) in a single line by using LINQ query in entity framework.

Example :
using (DBEntities db = new DBEntities())
{
    db.tblTemp.Where(x => x.ProductID == parmProductID && x.IsActive == true).ToList().ForEach(x =>
    {
        x.IsActive = false; x.UpdatedTimeStamp = DateTime.Now;
    });
    db.SaveChanges();
}

In the above example all the records which contains given ProductID and IsActive "true" records will be updated with IsActive "false" and UpdatedTimeStamp with current DateTime.






comments powered by Disqus


Search dotnetlearners.com