Linqdatasource updating row not found or changed
I recently encountered this error, and found the problem was not with my Data Context, but with an update statement firing inside a trigger after Commit was being called on the Context.The trigger was trying to update a non-nullable field with a null value, and it was causing the context to error out with the message mentioned above. Audit Criteria Name but that never works, it just returns an empty/blank field in the grid View. Post ID=3119233&Site ID=1 ) So to get around that I thought I'd use my own SELECTING statement, and that worked... I tried using an EVAL statement for Audit Criteria. The in-memory representation of the user who owns "Something" doesn't match what's in the database, and so you get this lurking bug.One way to prevent this is to write any code that might ever be called as a library method in such a way that it takes an optional Db Context: So now your method takes an optional database, and if there isn't one, goes and makes one itself. The helper method makes it easy to reuse this pattern across your app. except of course then I can't display the Audit Criteria Name in the details View which is a heck of a problem) I don't know how to deal with this.
The reason I'm using a custom selecting event is because I need to reference the Audit Criteria. or in his words: "One feature that will not work with custom shapes/projections, though, is inline editing support.
Even though the column is marked as NOT NULLable in your O/R-Mapping, LINQ will load it successfully and set the column-String to null.
The same symptom will appear when the data types of a field does not match the data type in SQL, or if fields are missing, since LINQ will not be able to make sure the SQL data has not changed since reading the data.
UPDATE [Sessions] SET [Is_Active] = @p4, [Disconnected] = @p5 WHERE ([Session_Rec Id] = @p0) AND ([App_Rec Id] = @p1) AND ([Is_Active] = 1) AND ([Established] = @p2) AND ([Disconnected] IS NULL) AND ([Member_Id] IS NULL) AND ([Company_Id] IS NULL) AND ([Site] IS NULL) AND (NOT ([Is_Device] = 1)) AND ([Machine_Name] = @p3) -- @p0: Input Guid (Size = 0; Prec = 0; Scale = 0) [0fbbee53-cf4c-4643-9045-e0a284ad131b] -- @p1: Input Guid (Size = 0; Prec = 0; Scale = 0) [7a174954-dd18-406e-833d-8da650207d3d] -- @p2: Input Date Time (Size = 0; Prec = 0; Scale = 0) [9/4/2008 PM] -- @p3: Input String (Size = 0; Prec = 0; Scale = 0) [CWMOBILEDEV] -- @p4: Input Boolean (Size = 0; Prec = 0; Scale = 0) [False] -- @p5: Input Date Time (Size = 0; Prec = 0; Scale = 0) [9/4/2008 PM] -- Context: Sql Provider(Sql CE) Model: Attributed Meta Model Build: 3.5.21022.8 Thats nasty, but simple: Check if the data types for all fields in the O/R-Designer match the data types in your SQL table. A column should be either nullable in both the O/R-Designer and SQL, or not nullable in both.
For example, a NVARCHAR column "title" is marked as NULLable in your database, and contains the value NULL.