Accepted answer

Are you getting the, "" exception? The problem is that linq2sql wants to check to make sure it should modify the column before it actually modifies it. I usually don't care as much and am perfectly happy updating the entire row so I put the UpdateCheck = UpdateCheck.Never named parameter in my ColumnAttributes. I.e.,

[Column(UpdateCheck = UpdateCheck.Never)]

Then, when I want to save the item, I just do this:

Table<TEntity> da = MyDataContext.Context.GetTable<TEntity>();

if (entity.Id > 0)
    da.Attach(entity, true);




I think you may be running into the default Optimistic Concurreny behavior in LINQ to SQL (and I believe that LINQ to Entities work the same way).

Unless told otherwise, just before you update a row, it issues a SELECT statement against the previous values of all columns in the row to see if someone else modified them while you kept them in memory.

However, it sounds like it doesn't know how to compare two Binary instances.

If this is the case, you have two options:

  • Use a more explicit version of Optimistic Concurrency by identifying the row version based on a designated timestamp row (preferred)
  • Disable Optimistic Concurrency

Here's the documentation for Optimistic Concurrency for LINQ to SQL.


Just step back a second - how are you comparing these variables?

Are you computing a hash for the images? Comparing the hashes is much better than comparing the images byte for byte.

Related Articles