here is my code block
foreach(var n in animalbirdAdoptionDetails)
{
int animalBirdsId = n.AnimalsAndBirdsId;
int NoAnimal = Convert.ToInt32(n.NoAnimalsAdopted);
n.isActive = false;
context.NameOfAnimalsAndBirds.Update(e2 => new entity
{
quantity = e2.quantity + moreQuantity
});
context.SaveChanges();
}
DbSet' does not contain a definition for 'Update' and no accessible extension method 'Update' accepting a first argument of type 'DbSet' could be found (are you missing a using directive or an assembly reference?)
You are facing this error because in entity framework there is no update extension method available.
If you want to update existing records then you need to retrieve existing record by primary key reference or by any other table field reference. and assign new value to table fields.
Eg.
foreach(var n in animalbirdAdoptionDetails)
{
// remove unwanted variables and casting expression.
// if not required then.
int animalBirdsId = n.AnimalsAndBirdsId;
int NoAnimal = Convert.ToInt32(n.NoAnimalsAdopted);
n.isActive = false;
// Retrieve existing record
var entity = context.NameOfAnimalsAndBirds.FirstOrDefault(x => x.Id == n.Id);
// assign new value to existing property.
entity.quantity = entity.quantity + moreQuantity;
// in last just apply save changes.
context.SaveChanges();
}
Note: above code is for demonstration only. it is always good practice to update all entities at once and apply save changes (from outside of loop).