I am writing a custom logger implementation that traverses the set of pending changes and composes log messages, which are in turn specific to change action (insert/delete/update) and object type. For certain object types I need to obtain and log specific data from relations. E.g. I have record types Foo and Bar - the type Foo has field bar of type Bar, which is essentialy an N-to-1 relation. Suppose I have the code below:
Code: Select all
var changes = context.GetChangeSet();
foreach (var c in changes.All)
{
...
if (changes.Deletes.Contains(c))
{
Foo foo;
...
if ((foo = c as Foo) != null)
{
Write(string.Format("[{0}] Deleted \"{1}\" from \"{2}\".",
DateTime.Now, foo.name, foo.bar.name));
}
...
}
...
}
...
context.SubmitChanges();
Is there a way to obtain the Bar name that would work in this case? All data manipulations are performed entirely via data binding of IBindingList-s to UI components, rather than any of business logic, so logging such actions manually "in the same code" is not an option. The code only intercepts events when the user requests stuff to be updated in persistent storage.