Discussion: EntityRepository - Calling Delete invalidates iterator of GetEntities
From the perspective of a C++ programmer it seems totally natural, that the following construct is a bug:
for (const auto& entity : repository->GetEntities())
{
repository->Delete(entity->GetUniqueId());
}
Yet, I'd like to open a discussion here if this is the user experience, the interface should offer.
I thought about some ways to solve that, e.g. using RAII
auto manipulation_context = repository->GetManipulationContext();
for (const auto& entity : repository->GetEntities())
{
manipulation_context->Delete(entity->GetUniqueId());
}
// when the manipulation_context goes out of scope it actually executes all delete calls at once