.net – Linq – Row not found or changed

.net-3.5linqlinq-to-sqlnet

I have the following code:

        Guid id = imageMetaData.ID;

        Data.LinqToSQL.Image dbImage = DBContext.Images.Where(x => x.ID == id).SingleOrDefault();

        dbImage.width = imageMetaData.Width;
        dbImage.height = imageMetaData.Height;

        DBContext.SubmitChanges();

Looking at SQL Profiler, the following SQL is being generated:

exec sp_executesql N'UPDATE [dbo].[Images]
SET [height] = @p0, [width] = @p1
WHERE 0 = 1',N'@p0 int,@p1 int',@p0=603,@p1=365

Why does my where statement not include a "where id=…."???

What am I doing wrong?

My application throws a ChangeConflictException with the message… "Row not found or changed"

Best Answer

Check to make sure your model matches the DB. I've run across this if they are out of sync, in most cases the nullable flag. Check out this article for a possible cause.

I assume you are using the release version of .net 3.5 (Visual Studio 2008).