I am trying to write an Audit Log method that will log all changes in a Linq-To-Sql model.
I want to get all changes an loop through each type of change an call my method that creates a log record for each type of object.
I'm not sure if this is even possible.
This is my code. I get an error when I try to pass in the type as typeof(original) I don't know the type at desing time as it can be any of the linq objects in my model.
ChangeSet changedObjects = this._lmsDb.GetChangeSet();
foreach (var update in changedObjects.Updates)
{
Type type = update.GetType();
var original = this._lmsDb.GetTable(type).GetOriginalEntityState(update);
// Error from <typeof(original)>
AuditLog au = AuditLogger.GetAuditLogRecord<typeof(original)>(original, update, "Update", "", userName);
this._lmsDb.AuditLogs.InsertOnSubmit(au);
}
Is it possible to do this? And if so, any hints on how to go about this?