Subclassing AuditableDataContext

May 7, 2010 at 10:02 AM
Edited May 7, 2010 at 10:07 AM
Hello, thankyou for sharing your valuable Audit Library. It's working fine for me until now.

I'm trying to add some behaviour to dinamically configure tables/colums to audit. I've created a MyDatacontex, subclass of AuditableDataContext that incapsulates this behaviour. In my idea, MyDatacontex will be the superclass for the all specific datacontexts. Specifically MyDatacontex 1) defines three tables: AuditRecords, AuditColumns, AuditableColums 2) specializes DefaultAuditDefinitions() and InsertAuditRecordToDatabase() to audit only Tables and Columns whose names are specified in AuditableColums

 I've two problems with this approach (pls see above), any help/comment will be appreciated

greetings

Rob


1) I'm unable to dinamically execute the Audit method, given the table name . What i want to obtain is something like this:

Class MyDataContext: AuditableDatContext
{
	protected override void DefaultAuditDefinitions()
        {
            DataContext dc = DataContext.Instance;
            var auditTables = (from ac in dc.AuditableColumns select ac.TableName).Distinct();
            foreach (var at in auditTables)
            {
                var metatable = dc.Mapping.GetTables().Single(t => t.TableName == at);
                Type type = metatable.GetType();
                ITable table = dc.GetTable(type);
                table.Audit(); //this not works: ITable doesn't declare Audit()
            }
        }
}

2) suppose tu create a ConcreteDataContext subclass of MyDatacontex, and suppose this datacontext specifies a table Items. I'm unable to access Audit method from the ConcreteDataContext class (note that from MyDatacontex the Audit method is correctly accessible)

Class ConcreteDataContext: MyDataContext
{
        protected override void DefaultAuditDefinitions()
        { Items.Audit(); // this not works: not found any extention method Audit accepting first argument of type <Items>'
}
}