I have this method :
public async void Delete(params T[] items) { using (var context = new DataEntities()) { foreach (T item in items) { context.Entry(item).State = System.Data.Entity.EntityState.Deleted; } await context.SaveChangesAsync(); } } When I tried to delete an item :
dpc_participant part = (await SimpleIoc.Default.GetInstance<ICrud<dpc_participant>>().Search(x => x.dpc_id_participant_pk == currentitem.dpc_id_participant_pk && x.dpc_id_fk == currentitem.dpc_id_pk)).FirstOrDefault(); SimpleIoc.Default.GetInstance<ICrud<dpc_participant>>().Delete(part); I got this error
entity object cannot be referenced by multiple instances of IEntityChangeTracker.
Questions:
- What is the reason of this error?
- How can I fix it?