I have the following method on a WCF service:
/// <summary>
/// Receives the result of a request processing
/// </summary>
/// <param name="results">The resulting statuses for the processed account requests</param>
/// <returns>Whether the response was successfully handled</returns>
public bool SendRequestProcessingResult(IEnumerable<RequestProcessingResult> results)
{
foreach (var result in results)
{
// update entity
}
}
Is there some way to update all of the entities at once? Should I just add each update and then SaveChanges? What’s the best way to do this kind of “mass” update in EF 4.1?
Yep.
Be aware though that EF is an ORM, so it’s not really designed (performance-wise, I mean) for large batch updates of this nature. If you need to wring more performance out of it, you pretty much get to the point of writing a batch of SQL statements and executing them the old-fashioned way.
Most people (I mean other than Facebook, Twitter etc) typically don’t see problems with what you’re suggesting, though, and the lower-level you get, the more the intent of your code becomes lost in all the technical implementation.
It’s important to stress that it’s not necessary to improve performance of code unless you have measured it and found it to be lacking. Code for correctness, readability and maintenance first, then measure performance and make targeted improvements where they are found to be required.