There is one significant limitation with the Update method: You must create the object used in the lambda expression inside the lambda expression.You can't, for example, create a Customer object outside of the lambda expression and then return it from the lambda expression.
And, you'll note, at this point you haven't even called Save Changes, but you've already made one trip to the database.
Furthermore, you've retrieved (potentially) an unlimited collection of Customer objects -- that's got to hurt.
NET, you just issue that statement to the database server and assume that the server will optimize the heck out of it.
If you let EF LINQ mange the process, on the other hand, you'll first have to retrieve all the Premium Customer rows and then iterate through all of the resulting objects, updating each one individually.
You'll still only make one trip to the database on the call to Save Changes because Entity Framework will bundle up all of the Update statements into a single transmission wrapped inside a transaction.
However, each of those potentially unlimited number of Update statements will be executed individually because there's no way for the database engine to optimize these updates.And, as I've pointed out in a previous column, you can avoid that first trip at the cost of writing some additional code. E addresses both the "delete/update without retrieval" and the "batch update" problem. E is that it really just extends what you'd do normally. This code, for example, deletes all the Customers whose first name is Peter: If you prefer to use the LINQ "SQL-like" syntax, just call the Delete method from your LINQ statement (just as you would if you were using First or Distinct).However, it would be nice if you could do batch updates with EF LINQ and avoid that first retrieval without writing extra code. For example, to delete without retrieval you begin by calling the standard LINQ Where method from the collection containing the object you want to delete. Because it's only the Where clause that matters, your LINQ statement doesn't even need to include a Select clause.Given that single SQL statement, the database engine will delete all of the specified Customer rows in as optimized fashion as it can manage.In addition to saving a trip to the database, you also have a method for performing batch deletes.As I've said on numerous occasions (and summed up here), speeding up business applications comes down to reducing the number of trips to the database and optimizing your server-side data access once you're there.