gabrielk wrote:
Hi,
I can't find AuditDirectDeleteOfEntities in the help file. Where or what is it?
bug in the docs, I'll fix that a.s.a.p. Please check: Using the generated code -> Setting up and using Auditing -> Location of your auditing logic: OnAuditDirectDeleteOfEntities.
Isn't it strange that an entity can get deleted without the Delete events being executed? I would say this should be mentioned somewhere in the manual. And if it is already it is not obvious yet.
It's obvious IMHO that these events aren't raised. You seem to confuse two things:
a) DeleteMulti()
and
b) DeleteMulti(filter [, relations])
The first deletes all entities in the collection it's called on. The second deletes all entities from the DB of the type the collection belongs to with the filter specified.
In the case of a) it calls the OnDelete method every time an entity is about to be deleted, namely for every entity in the collection. In the case of b) it can't do that, because the filter might match 1 million rows. Do you want to fetch them first into memory, then call the OnDelete on every row and then delete them?
That's pretty slow I think, so it won't do that. So because of the uncertainty which rows match with the filter, the OnDelete method can't be called.
Is this done together with the Auditing in 2.5, or can it be done with 2.0 also?
In v2.5, you can audit a call to DeleteMulti(filter), however it's not possible to prevent the deletion there, auditing is always 'mosterd na de maaltijd' so to say
An authorizer can prevent deletion, but it works on types. So you can't prevent 'certain' entities to be deleted, as you then first have to check if the entities not to be deleted match the filter.
Is this direct to db behavior the same for SaveMulti()? If it's not it's inconsistent, if it is i have problem
SaveMulti always works on entities in memory, similar to DeleteMulti(), so that's consistent. SaveMulti doesn't work on the DB directly.
Btw, what I find strange is this code in the ORM Supportclasses:
private int PerformDeleteMulti()
{
(...)
bool wasSuccesful = entityToDelete.Delete();
(...)
}
Thanks,
Gab
That's the call for DeleteMulti() (no filter). Not the one which deletes entities directly.
If you want to prevent the deletion of a certain entity in certain cases, it's perhaps better to override DeleteMulti(filter) and DeleteMulti(filter, relations) in the collection of the entity and simply prevent one calls these methods (so entities always have to be fetched first), i.e. by throwing an exception.
That won't affect DeleteMulti() (no filter!), as that's a different routine.
Are these overloads stupid, or not chosen correctly? Of course. But as they're part of the oldest core of LLBLGen Pro, there's no ability to change them.