Problem auditing FK fields

Nov 17, 2010 at 4:17 PM

I created an ASP.NET 4.0 dynamic data project, created a LINQ to SQL class using Northwind, implemented the auditing, and everything seemed to work fine, including changed FK fields being recognized and logged.

Then I added the functionality to my existing site, and things aren't working completely.

The main problem is that foreign key fields aren't being recognized.

Example:

My table Products contains these fields :

  •  
    • ProductId,
    • ProductTypeId (FK to ProductTypes table)
    • ServiceCategoryId (FK to ServiceCategories table)
    • Product

Product is the only table on which auditing is enabled in my data context class file.

When I add a new record to Products, a record appears in AuditRecords with the new ProductID value. Four associated records appear in AuditRecordFields: Product, which contains the name of the new product, Product Type, which is blank, and Service Category, which is blank.

If I edit a record in Products and make a change to either ProductTypeId or ServiceCategoryId, a record is created in AuditRecords indicating a change is made, but there are no related records in AuditRecordFields.

So the auditing system realizes the record is being changed, but for some reason isn't tracking the new/old values of the two FK fields.

Help! :)