I am curious as to what the proper way to update a list of entities at one time is.
public ActionWas Update(IEnumerable<surcharge_template> templates)
{
try
{
var templatesToBeUpdated = _context.surcharge_template.Where(x => templates.Select(template => template.st_key).Contains(x.st_key));
//Right here I need to map all of the differences from the original templates
//to the new templates
_context.Entry(templatesToBeUpdated).State = EntityState.Modified;
}
catch (Exception ex)
{
return _exceptionConverter.Convert(ex);
}
_context.SaveChanges();
return ActionWas.Successsful;
}
I put a comment at the point where I am not sure the way to handle this. I get the original templates from the database and then I need to map them, then commit and save.
So what is the proper way to map them?
UPDATE:
I would like to do this with EF only making one call to the database. Enumerating the list would cause multipe update statements.