The standard way to update a record using Linq to SQL is to load a record from the database, assign the new column values, and submit the changes:
using (var database = new DataContext()) { var foo = database.Foos.Where(f => f.OID == OID).FirstOrDefault(); foo.ID = newID; database.SubmitChanges(); }
In case you are accessing tables containing n/varchar(max) or varbinary(max) columns (previously n/text and image), such as this:
CREATE TABLE [dbo].[FooMax]( [OID] [int] IDENTITY(1,1) NOT NULL, [ID] [nvarchar](50) NOT NULL, [SomeText] [nvarchar](max) NULL, [SomeBinary] [varbinary](max) NULL, CONSTRAINT [PK_FooMax] 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 post starts a series of posts presenting solutions to this problem.
Pingback: Updating a Single Column in Linq to SQL using a Stored Procedure « devioblog
Pingback: Updating a Single Column in Linq to SQL using a View « devioblog
Pingback: Updating a Single Column in Linq to SQL – Summary « devioblog
Pingback: Batch Insert using Linq To SQL (2) « devioblog