Dlinq and IChangeNotifier

by Miha Markič 16. September 2005 11:15

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.

Tags:

.net

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Miha Markic

About me
Righthand
 
Microsoft MVP
 
Developer Express' DXSquad
INETA Country Leader for Slovenia
INETA Country Leader for Slovenia

Slovene Developer Users Group Lead
Friends of Red-Gate
LLBLGenPro Partner

Miha currently works as a free lance consultant and software developer specialized in .net area.
He graduated in Computer and information science at the University of Ljubljana, Slovenia. He has accumulated experience in various programming languages such as Java, Visual Basic 3-6 (MCP), Visual C++, Delphi, C# and VB.Net through years.
He has experience in practically all (technical) stages of project development, including planning, framework development, user interface, business processes, as well as testing and documenting. He has worked on big and small projects in Slovenia and abroad (e.g. participated in completing level 3 IS for the Nucor steel plant, Hertford, USA).
Currently he enjoys programming in .net environment using C#. Since 2000 he has been active in Developer Express' DX Squad and has been ECDL trainer and tester. He also gives lectures on conferences and other events in Slovenia.

Month List

Tag cloud

Most comments

Paulius Paulius
1 comments
us United States
Meh Meh
1 comments
us United States
bart dm bart dm
1 comments
nl Netherlands

RecentComments

Comment RSS