Authorizer working in ways not expected

Posts   
 
    
Posts: 4
Joined: 12-Nov-2008
# Posted on: 14-Nov-2008 12:26:58   

I have an authorizer that for all CommonEntityBase objects does this:

public override bool CanLoadEntity(IEntityCore entity) { Type t = entity.GetType(); PropertyInfo[] props = t.GetProperties(); foreach (PropertyInfo prop in props) { if (prop.Name == "IsDeleted") return !(bool)prop.GetValue(entity, null); } return true; }

I have an entity called QuestionEntity that has an IsDeleted property. When changes are made to a QuestionEntity an auditor is used to save the details of the change.

If I set the IsDeleted property to true for a QuestionEntity and then save it then by the time the Audtior is called the Properties of the questionEntity will have had thier state wiped by the authorizer above being activated and returning false (due to the IsDeleted property being set to true).

What I do not understand is why saving the QuestionEntity calls the authorization logic above. In the LLBLGen documentation it states that the CanLoadEntity method of an authorizer is called when:

"...the particular entity object is about to be filled with entity data from the database",

and I would not expect saving an entity to be filling the entity with data from the database. Can anyone explain what is going on with this?

Is this a bug or am I just failing to understand what is going on?

Details: LLBLGEN Pro version: v2.6 Final (October 6th, 2008 ) LLBLGEN run-time version: 2.6.8.1013 Templates: Self-servicing Database: Ms Sql Server 2005

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 14-Nov-2008 12:48:33   

Would you please post the code of saving the entity?

In SelfServicing: After Saving an entity in the database, the entity is refetched again from the database once you try to access any of its fields. This is to ensure that values are set inside the database are updated into the entity (for example default values for columns, or values set by triggers).

Posts: 4
Joined: 12-Nov-2008
# Posted on: 14-Nov-2008 13:01:07   

Thanks for the reply it has clarified everything for me perfectly.

There is nothing special about the code for saving. All that matters is that the IsDeleted property is set to true before the save. The problem I was having was that my auditor was trying to use data stored in the properties of a the saved QuestionEntity. This was causing the refetch you describe, which was causing all the values to be wiped out as the authorizer was returning false.

Knowing what I know now I will rework things to avoid the problem.

Thanks for the help.