This project is read-only.

Issue With CustomizeProperties

Jan 18, 2009 at 2:24 PM
Edited Jan 18, 2009 at 2:31 PM
Hi --

Could somebody please assist me trying to customize the properties. Following the example on the homepage, I've written this:

public class ControlAuditResolver : AuditPropertyResolver<Control>
    {
        protected override void CustomizeProperties()
        {
            CustomizeProperty(c => c.Control_Frequency_ID, d => Helpers.Options.Value("optionscontrolfrequencies", d), "Frequency");
        }
    }

I breakpointed that, along with the Options.Value code and it never gets called. The rest of the auditing functionality works, and I end up with an entry like:
Control_Frequency_ID    old value: 1 new value: 3


One point:
In the example, Matt wrote:
CustomizeProperty(p => p.CategoryID, categoryId => GetCategoryByID(cid).CategoryName, "Category");

I'm having mental problems with lambdas, but I couldn't figure out the second parameter, and
how categoryID => ...(cid). I've tried a few analogous permutations, but everything ends with the
same result in which it seems that the code doesn't get called at all.

Thanks,
James

edit:
BTW: This is in my Project.Models namespace, which is the same place as my partial DataContext, the one that calls InsertAuditRecordToDatabase (which is obviously getting called).



Jan 19, 2009 at 8:07 PM
James,

I apologize I left out some details regarding "Custom Property Resolvers." I have been meaning to create a Wiki page dedicated to functionality to provide clear instructions but I have not found time yet.

To answer your question, right now you are probably missing an attribute over your 'Control' class. When the auditing mechanism attempts to audit the properties of a class it looks for an attribute specifying a custom AuditPropertyResolver, otherwise it uses default auditing rules.

To resolve this, open up your Control.cs and put the following attribute on top of the class.

[AuditResolver(typeof(ControlAuditResolver))]
public class Control
{ ...... }
Jan 19, 2009 at 9:31 PM
Two things worth noting:

I realize that some people will not like "polluting" their model with auditing attributes, and I understand this. I am looking into other mechanisms for custom property auditing and will hopefully post an alternate method shortly.

Additionally, please do not add the attribute in your LINQ to SQL designer generated classes, since it will be lost when you modify the designer surface. Instead, create a new partial class file and put the attribute on top of this "half" of the partial class. This way you are free to modify your DBML without losing the attribute.
 
Jan 19, 2009 at 9:54 PM
Thanks, Matt.

I did my best to step through the code and research the functions you used. My solution ended up being the exact opposite!

[AuditResolver(typeof(Control))]
public class ControlAuditResolver {}

Thanks.