Categories
.net

Dlinq and IChangeNotifier

I am doing some tests with DLinq. I have created my classes properly decorated with attributes. I have also implemented IChangeNotifier to make tracking faster (all this was created by my CodeSmith template which I will post later). However I couldn’t persist a simple change which left me scratching my head for a while. Here is my pseudo code:


Load an entity
Change its property
Call DataContext.SubmitChanges


Simple, huh. Yet nothing was saved. I’ve checked with SqlProfiler to see if anything is going on – and no, there was no update command issued which indicated that DataContext was unaware of any change. At one point in time I’ve commented out IChangeNotifier implementation and the thing started working normally, as one would except. After another while I’ve found the problem – I was calling OnChanging() too late:


   set
   {
    if (value != id)
    {
     id = value;
     OnChanging();
    }
   }


Moving OnChanging one row up fixed the problem:

   set
   {
    if (value != id)
    {
     OnChanging();
     id = value;
    }
   }


This seems logical as OnChanging implies that is should occur before change is persisted. Another mystery solved.

Leave a Reply