UnitOfWork icon indicating copy to clipboard operation
UnitOfWork copied to clipboard

Delete Error?

Open JiangJiaqi90 opened this issue 7 years ago • 8 comments

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;

JiangJiaqi90 avatar Oct 28 '18 02:10 JiangJiaqi90

  1. First of all, ensure database has the record with id;
  2. Secondly, ensure whether the table has combining primary keys;

rigofunc avatar Oct 29 '18 01:10 rigofunc

  1. First of all, ensure database has the record with id;
  2. 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); }

JiangJiaqi90 avatar Oct 29 '18 02:10 JiangJiaqi90

OK, I'll test this. Right now, using Delete(entity) for bypassing this issue.

rigofunc avatar Oct 29 '18 02:10 rigofunc

@xyting ok, thanks!

JiangJiaqi90 avatar Oct 29 '18 02:10 JiangJiaqi90

@xyting any update on this?

attiqeurrehman avatar Jan 07 '19 07:01 attiqeurrehman

@attiqeurrehman next month.

rigofunc avatar Jan 07 '19 09:01 rigofunc

期待

zanderzhg avatar Jan 07 '19 10:01 zanderzhg

any update?

attiqe avatar Jan 13 '20 14:01 attiqe