Row not found or changed LINQ C# error on simple statement

后端 未结 4 765
执念已碎
执念已碎 2021-02-01 20:14

First of all, there is no chance that this is a multi-user issue, as I\'m working locally on a dev version of the database.

I am getting the not very explanatory R

4条回答
  •  梦谈多话
    2021-02-01 21:10

    Another possibility that I've found to add to the excellent list of answers here:

    When using a not-nullable column in a database - then mapping that to a datatype that is intrinsically nullable (in this example DB type is LONG BLOB NOT NULL mapped to a byte array in c#) you can end up in a situation where updating the database with the exact same byte array causes this error to be thrown.

    Example: You have a website that allows the user to upload an image to the database. Your table has a blob (image in sql server, whatever) that is not nullable. The user chooses to update the record with the exact same image that is already there. The update check will fail. I fixed this by first doing a .SequenceEqual() check and then only calling .SubmitChanges() on the context object if the incoming byte array was not equal to the existing one.

提交回复
热议问题