ChangeConflictException: Row not found or changed

sid
sid
120 Points
9 Posts

I'm using .dbml to map db to linq. And in controller action I'm updating count:

var rsl = _dbContext.tbl_test.FirstOrDefault(b => b.id == id);
rsl.ViewCount = rsl.ViewCount + 1;
_dbContext.SubmitChanges();

Some time I'm getting error:

System.Data.Linq.ChangeConflictException: Row not found or changed

Also, I'm able to reproduce the error by hitting controller action multiple time. 

Any Idea what causing this error?

Views: 9110
Total Answered: 2
Total Marked As Answer: 2
Posted On: 29-May-2019 10:16

Share:   fb twitter linkedin
Use _dbContext.Refresh(RefreshMode.OverwriteCurrentValues, rsl)
 - Stevan  30-May-2019 08:14
Answers
hmm
hmm
30 Points
0 Posts
         

I was faced same issue and resolved by making sure to refresh my object immediately before updating it.

var rsl = _dbContext.tbl_test.FirstOrDefault(b => b.id == id);
_dbContext.Refresh(RefreshMode.OverwriteCurrentValues, rsl);
rsl.ViewCount = rsl.ViewCount + 1;
_dbContext.SubmitChanges();
Posted On: 30-May-2019 08:28
Thanks..
 - sid  06-Jul-2019 21:00
Rashmi
Rashmi
1068 Points
19 Posts
         

LINQ to SQL looked for the record to updated comparing all the columns to their original values, and when no records were found, the exception was thrown:

System.Data.Linq.ChangeConflictException: Row not found or changed

Use 

_dbContext.Refresh(RefreshMode.OverwriteCurrentValues, rsl)

It maybe resolve this issue.

Posted On: 06-Jul-2019 20:58
 Log In to Chat