Explore sort expression used in prefetch while auditing

Posts   
 
    
msickler
User
Posts: 11
Joined: 24-Sep-2007
# Posted on: 26-Jan-2008 00:25:07   

I'd like to use the method AuditReferenceOfRelatedEntity when auditing to explore the relation ship between the item that is being related and the item that is being related to.

I have two tables with the second table containing a foreign key to the first. When a GetMulit is used to pull records from the first table a prefetch path is given that includes a sort expression to pull the items from the second table in a specific order. I'd like track this information in the auditor. Is that possible?

I'm interested in tracking what was sorted on, for an example I'd like to know that the column SortOrdinal was used Ascending.


PrefetchPath prefetch = new PrefetchPath((int)EntityType.SlideshowEntity);
SortExpression sorter = new SortExpression(SlideshowItemFields.SortOrdinal | SortOperator.Ascending)
prefetch.Add(SlideshowEntity.PrefetchPathSlideshowItem, 0, null, null, sorter);

Walaa avatar
Walaa
Support Team
Posts: 14983
Joined: 21-Aug-2005
# Posted on: 28-Jan-2008 10:32:26   

AuditReferenceOfRelatedEntity is called for each related entity being referenced not for the entire collection. So the sorting information isn't available there.

You may save the SortClause in a global variable or so, and access it from the audit method, or elsewhere.

msickler
User
Posts: 11
Joined: 24-Sep-2007
# Posted on: 28-Jan-2008 15:34:42   

If that is the case is it possible to use the Dependency Injection mechanism to inject a piece of custom code at that right place to track this information?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 28-Jan-2008 15:57:30   

That is possible, however why do you want to track that info? Auditing is targeted to be a logging helper, so you get info after the fact what happened when and why/how/by whom, though it shouldn't be used as controlling information for control flow in your application, do you want to use it for that?

Frans Bouma | Lead developer LLBLGen Pro
msickler
User
Posts: 11
Joined: 24-Sep-2007
# Posted on: 28-Jan-2008 17:34:17   

You got me, I know I'm using it for functionality other than it was intended for. I was hoping to use it because it allowed me to get it up and running much quicker than if I were to track down an AOP framework and learn it which is what I really need to do.

If you can recommend something I would appreciate it. It appears that StructureMap won't see this functionality till v2.5:

http://codebetter.com/blogs/jeremy.miller/archive/2008/01/27/interception-techniques-in-structuremap-2-5.aspx

This is the scenario I'm currently playing with: based on the context of the application the data a user is currently working would either come from a "live" table or a "draft" table. In order to keep the LLBLGen code simple it is written against the live table and has no knowledge of the draft table. If in the right context the draft data is overlaid on top of the live data meaning entity fields are changed to the latest draft or additional rows are added/removed to child collections if necessary.

I'm looking to intercept LLBLGen at certain points in order for this to happen. An example scenario might be if a user attempts to delete a row, if this happens within the draft context I would like that action "drafted" and applied at a later time if the user approves it, essentially making all the changes that would be performed within that session to the live table.

The draft table is essentially two columns: PropertyName, PropertyValue. A row is present for each property change on an entity. I've used this system in the past to draft changes but it required quite a bit of code intermixed with the standard LLBLGen code used to pull from the live table. I'm trying to eliminate a lot of repeated code by having this run in the background.