Print Page | Close Window

PropertyChanged event not firing in Distributed mode.

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2675
Printed Date: 21-Jul-2026 at 9:46am


Topic: PropertyChanged event not firing in Distributed mode.
Posted By: BringerOD
Subject: PropertyChanged event not firing in Distributed mode.
Date Posted: 12-May-2011 at 10:29pm

When I handled the PropertyChanged event on an entity it fires as expected when my application is connected to the database server in the App.Config.

When I switch it to use the webservice in distributed mode and comment out the connection to the database like below, the event no longer fires.   Is this by design and if so how to I trap the property changed event.

      <objectServer remoteBaseURL = "http://XXX.XXX.XXX"

                    serverPort = "80"

                    serviceName = "EntityService.svc" >

         <clientSettings  isDistributed="true" />

      </objectServer>

 




Replies:
Posted By: sbelini
Date Posted: 13-May-2011 at 4:05pm
Hi Bryan,
 
I could not reproduce your issue here.
 
In my test case PropertyChanged fires in both 2 and n-tier.
 
When you set isDistributed ="true" in the App.Config did you update the connectionString in the Web.Config file? (btw, you don't really need to comment out the connectionString in the App.Config file - setting isDistributed="true" will suffice)
 
Can you provide a simple test case (against NorthwindIB) reproducing the issue?
 
Silvio.


Posted By: BringerOD
Date Posted: 14-May-2011 at 11:37am
uploads/916/PropertyChangeEventTest1.zip - uploads/916/PropertyChangeEventTest1.zip

I uploaded a sample.

Set distributed to false.  Put a breakpoint in the Customer class on the property changed event. Edit the company name field, leave the column to trigger the property event.  The event will fire.

Set distributed to true and do the same thing.  The event will NOT fire.

  void Customer_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
      {
         if (e.PropertyName == "CompanyName")
         {
            var Test = 1;

         }
      }


Bryan Reynolds


Posted By: sbelini
Date Posted: 16-May-2011 at 11:35am
Hi Bryan,
 
What's happening in your code is that you are setting the event handler in the entity's constructor and serialization (i.e. n-tier) does not use the constructor. (in this case you'd only see the event fired on new enitities you created in the client)
 
Also, bear in mind that even in 2-tier, if you load 1000 entities, you'd be setting 1000 event handlers. (one for each entity) That's not very efficient and I suggest you use EntityGroup.EntityPropertyChanged instead:
 
var eGroup = _entities.GetEntityGroup(typeof(Customer));
eGroup.EntityPropertyChanged += new EventHandler<EntityPropertyChangedEventArgs
(eGroup_EntityPropertyChanged);
 
...
 
void eGroup_EntityPropertyChanged(object sender, EntityPropertyChangedEventArgs e) {
  if (e.Property.Name == "CompanyName") {
    var Test = 1;
  }
}
 
Silvio.


Posted By: BringerOD
Date Posted: 16-May-2011 at 11:43am
Makes sense. 
 
Thanks!
 
Bryan



Print Page | Close Window