Questions for Auditing

Posts   
 
    
xc_lw2000
User
Posts: 48
Joined: 12-Dec-2006
# Posted on: 13-Jan-2009 15:46:50   

I want to use autiting for my database.

My database can be changed by both a winform application and a webform application. The winform application is for common user purpose, and the webform application is for managers only. The two apps are using the same entities which are generated by LLBLGerPro.
I want to auditing for db changes which come from the webform application,and changes from winform will be ignored.
Since I refrenced the document,there are three options:

1.Setting the AuditorToUse property of an entity object manually. This is straight forward, but error prone: if you forget to set an auditor, auditing isn't performed. Also, entities fetched in bulk into a collection are created using the factories so you have to alter these as well. You could opt for overriding OnInitializing in an entity to add the creation of the Auditor class. 2.By overriding the Entity method CreateAuditor. This is a protected virtual (Protected Overridable) method which by default returns null / Nothing. You can override this method in a partial class or user code region of the Entity class to create the Auditor to use for the entity. The LLBLGen Pro runtime framework will take care of calling the method. One way to create an override for most entities is by using a template. Please see the LLBLGen Pro SDK documentation for details about how to write templates to generate additional code into entities and in separate files. Also please see Adding Adding your own code to the generated classes for details. 3.By using Dependency Injection. Using the Dependency Injection mechanism build into LLBLGen Pro, the defined Auditors are injected into the entity objects for you. This option is the least amount of work.

So I think the last two are not suit for me. But with the option 1,when I aduting single entity,it's no proplem. But how can I aduting correctly for follow scences: 1.Tens,hundreds even more entities be changed once.May be I need to loop all these entities? 2.UpdateEntitiesDirectly or DeleteEntitiesDirecly which I don't know how many entities will be changed for this time.

Regard for your reply,thanks.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 13-Jan-2009 22:01:13   

1) As long as you have added an auditor to each entity, you do not need to anything else when saving multiple entities. The save process traverses the entity graph, and additionaly persists any audit information that your auditor creates.

2) UpdateEntitiesDirectly and DeleteEntitiesDirectly can both be audited - see the documentation

xc_lw2000
User
Posts: 48
Joined: 12-Dec-2006
# Posted on: 14-Jan-2009 15:32:21   

MTrinder wrote:

1) As long as you have added an auditor to each entity, you do not need to anything else when saving multiple entities. The save process traverses the entity graph, and additionaly persists any audit information that your auditor creates.

2) UpdateEntitiesDirectly and DeleteEntitiesDirectly can both be audited - see the documentation

 May be I haven't expresion clearly.
 There are two applications,a winform and a webform. If my user update/delete/add an entity by the winform application,it is not necessay to audite this action for me,but if my user update/delete/add an entity by the webform application,this action should be audited.
  If I add an auditor to each entity,then no matter which application the user used,all the actions will be audited,this is not what I want.
  So I must select option 1---specify auditor for the entity which will be added/updated/deleted in my webform code and not for my winform code.But when I use UpdateEntitesDirectly or DeleteEntitiesDeirecly to do these actions,how can I specify audito for each entity which be updated/deleted?I don't know how many entities will be deleted/updated and what they are.
Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 14-Jan-2009 16:48:16   

3.By using Dependency Injection. Using the Dependency Injection mechanism build into LLBLGen Pro, the defined Auditors are injected into the entity objects for you. This option is the least amount of work.

Definitly you should use Option 3.

Since DI is configured through the Config file of your application, so you can turn it on in the web.config of the Web application, and Turn it off (don't use it) in the app.config of your Win app.

Please check Setting up and using Dependency Injection

xc_lw2000
User
Posts: 48
Joined: 12-Dec-2006
# Posted on: 15-Jan-2009 15:02:14   

Walaa wrote:

3.By using Dependency Injection. Using the Dependency Injection mechanism build into LLBLGen Pro, the defined Auditors are injected into the entity objects for you. This option is the least amount of work.

Definitly you should use Option 3.

Since DI is configured through the Config file of your application, so you can turn it on in the web.config of the Web application, and Turn it off (don't use it) in the app.config of your Win app.

Please check Setting up and using Dependency Injection

Yeah!What a good idea. Thank you very much.

NBsmile (a Chinese saying,means very very smat or admirable)