Linq - Row not found or changed
Asked Answered
C

3

15

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"

Carlotacarlotta answered 3/2, 2009 at 21:46 Comment(2)
We'd need to see the code before that... how/when is your datacontext instantiated? Where does imageMetaData.ID get set?Kaleena
Do you have any triggers on this table?Mohn
C
38

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

Communicable answered 3/2, 2009 at 22:11 Comment(2)
Thanks, was just a simple null not set issue. Must have a better way of keeping db's in sync!Geometrize
If the schema is simple, consider creating the DB schema from the DBML. This makes the DBML is the source of truth.Communicable
A
1

Found the solution in: http://social.msdn.microsoft.com/Forums/en-US/linqprojectgeneral/thread/c672c8ee-bf2a-41b4-bb8b-aa76cc5d9b95 (posted by Todd Fleenor)

The problem can be solved this error by redragging the table from the server explorer to the designer and rebuilding. So the designer was out-of-synch with the SQL Table...

Apodaca answered 16/6, 2011 at 15:55 Comment(1)
Worked for me. The best way to solve the situation is to create a new linq to sql file, drag and drop the tables, and then copy the resulting XMLDacca
M
0

I had the same problem and just deleted table in .dbml file (designer) and dropped from database again, then built my application. It solved my problem.

Monto answered 29/8, 2012 at 8:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.