The call to ChangeTracker.DetectChanges() is to ensure that the change tracker is aware of the changes made to the entities, e.g. if you set.Category to a new Category on an existing Product, the new Category wouldn’t be tracked until DetectChanges() is called or it’s added explicitly through DbSet or ChangeTracker.