The object cannot be deleted because it was not found in the ObjectStateManager

It means that entity is not attached (it was not loaded by the same context instance). Try this:

protected MyEntities sqlEntities;

public virtual void Delete(TEntity entity)
{
    sqlEntities.Attach(entity);
    sqlEntities.DeleteObject(entity);
    sqlEntities.SaveChanges();
}

Leave a Comment