I am trying to use entity to update many records up to 30 if the conditions inside the statement match but i am having an issue finding the correct method to use at the end what I have is this
public ActionResult Edit(profile profile)
{
//change all records where getid== x.registrationID
var getprofile =
(from x in db.Articles where getid == x.RegistrationID select x).Any();
getprofile.firstname = profile.firstname;
getprofile.lastname = profile.lastname;
}
The error i get is on getprofile.firstname and getprofile.lastname saying the bool does not contain a definition for firstname or lastname. If i put in FirstorDefault() everything works fine but of course it only changes the 1st record…
How can I change many records?
You can use
ToList()to get a collection ofArticles:This queries the database, gets the matching
Articlerows and puts them in a collection – aList<Article>You can then modify the objects in the collection and finally call
db.SaveChanges()to update the database.