Delete Error?
I use like this: var repo = _unitOfWork.GetRepository<Product>(); repo.Delete(id); _unitOfWork.SaveChanges(); But it Error: Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException:“Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. at Repository.cs line 548 code is : var entity = Activator.CreateInstance<TEntity>(); property.SetValue(entity, id); _dbContext.Entry(entity).State = EntityState.Deleted;
- First of all, ensure database has the record with
id; - Secondly, ensure whether the table has combining primary keys;
- First of all, ensure database has the record with
id;- Secondly, ensure whether the table has combining primary keys;
Yes, the two is ok. I use Mysql. It still error. When it runs code at Repository.cs line 548 ,It's Error var entity = Activator.CreateInstance(); property.SetValue(entity, id); _dbContext.Entry(entity).State = EntityState.Deleted; When it runs code at Repository.cs line 554, It's OK var entity = _dbSet.Find(id); if (entity != null) { Delete(entity); }
OK, I'll test this. Right now, using Delete(entity) for bypassing this issue.
@xyting ok, thanks!
@xyting any update on this?
@attiqeurrehman next month.
期待
any update?