Updating a Single Column in Linq to SQL – Summary

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.

This method is undesirable if your table contains long text or binary columns, since they are loaded into the Linq to SQL object without being used.

Starting with a table containing nvarchar(max) and varbinary(max) columns

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)
)

I listed a couple of methods to reduce database access to the columns actually required in the UPDATE process:

The dbml mappings for these solutions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.