Updating using linq patent number dating
Furthermore, you've retrieved (potentially) an unlimited collection of Customer objects -- that's got to hurt.
Furthermore, when you do finally call Save Changes, Entity Framework isn't smart enough to issue the single SQL Update statement I used as my example.
This code, for example, sets the Credit Limit of all Customers with a Cust Credit Status of Premium to 2000: Only the columns corresponding to properties you set in the object created in the Update method's lambda expression will be updated -- any properties you don't set will be left alone.
This means that if you have property you want to set to its default, then you must explicitly set that property's value.
CREATE TABLE [dbo].[Foo Max]( [OID] [int] IDENTITY(1,1) NOT NULL, [ID] [nvarchar](50) NOT NULL, [Some Text] [nvarchar](max) NULL, [Some Binary] [varbinary](max) NULL, CONSTRAINT [PK_Foo Max] PRIMARY KEY CLUSTERED ([OID] ASC) ) above code means that the whole record is loaded into memory just to update a single column.
Bear in mind that n/varchar(max) and varbinary(max) column can hold data up to 2GB each!
This code, for example, sets the Credit Limit property and then goes on to set the Cust Credit Status to nothing: Like the Delete statement, the Update method returns an integer telling you how many rows were updated and must follow the Where clause.
There is one significant limitation with the Update method: You must create the object used in the lambda expression inside the lambda expression.
If you have a lot of Premium Customer rows, you'll have an operation with a response time that should be measured with a calendar, not a stop watch (assuming that your application doesn't just time out waiting for a response).
Some final notes: While my Where clauses have been very simple, for both the Delete and the Update methods you can make your Where clause as complicated as you want.
As your Where clause becomes more complicated, though, you might want to check that integer result to see if it's non-zero -- a zero result would mean that you didn't find anything to delete.
You can't, for example, create a Customer object outside of the lambda expression and then return it from the lambda expression.
You also can't pass the Update method a lambda expression of more than one line or pass a reference to another method in your application.