0


Note on this question being marked as "duplicate": Unlike the question in Linq row not found or changed my question is about a specific scenario that triggers the "Row not found or changed" message and is seeking a resolution for that.

Additionally the answer to that question is not useful to my question because my scenario already implements the "minimal unit of work" principal suggested there.


In my web service I am trying to attach a LINQ to SQL entity coming in from a client application to my DataContext like so:

public void Update(MyEntity myEntity)
{
    using (var context = new MyDataContext())
    {
        context.Attach(myEntity, true);
        context.SubmitChanges();
    }
}

A precondition for LINQ to SQL to be able to do this is for MyEntity to have a property mapped to a ROWVERSION column in the DB table. In my case I called this property RowVersion.

If the instance of MyEntity coming in from the client has RowVersion set to null then when I call context.SubmitChanges() a System.Data.Linq.ChangeConflictException stating:

Row not found or changed.

Why is this happening and how can I prevent this from happening regardless of the client application changing the value of RowVersion?

One thing that I've noticed is that if I get the "old" entity from the context and then assign its RowVersion value to the new entity then the exception is avoided. Is this the right thing to do? Why?

Community
  • 1
  • 1
urig
  • 16,016
  • 26
  • 115
  • 184

0 Answers0