ChangeConflictException: Row not found or changed

sid
sid
20 Points
10 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: 53
Total Answered: 1
Total Marked As Answer: 0
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
Member
2 Points
1 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
 Log In to Chat