Different ListChanged event behavior in 3.5.2 vs 3.6.0

Different ListChanged event behavior in 3.5.2 vs 3.6.0

Old forum URL: forums.lhotka.net/forums/t/6060.aspx


Andreas posted on Monday, December 29, 2008

I experienced a different ListChanged event behavior of BLB between v3.5.2 and v3.6.0 when a property of a containing child object changed. In version 3.5.3 the ListChanged event was called only once, as I expected. In version 3.6.0 the ListChanged event is called two times??

A Happy and Successful New Year to the Fantastic CSLA Team,

Andreas

 

Andreas replied on Sunday, January 11, 2009

Hi,

Unfortunately I was not able find the problem by debugging Csla 3.6 why OnListChanged is called two times after a property of a child item was changed. This behavior gets me in trouble with my current business logic and causes performance decreases as well. I would really appreciate if someone can figure out if this is a bug and may get fixed sometime (or if I have to life with it and need to change my business logic).I've written a small test program:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Csla;

namespace OnListChanged

{

   public class Person : Csla.BusinessBase<Person>

   {

      public Person()

      {

      }

      public static PropertyInfo<string> NameProperty =

            RegisterProperty<string>(new PropertyInfo<string>("Name"));

      public string FirstName

      {

         get

         {

            return GetProperty<string>(NameProperty);

         }

         set

         {

            SetProperty<string>(NameProperty, value);

         }

      }

   }

   public class PersonList : Csla.BusinessListBase<PersonList, Person>

   {

      public PersonList() { }

      protected override void OnListChanged(System.ComponentModel.ListChangedEventArgs e)

      {

         base.OnListChanged(e);

      }

      protected override void OnChildChanged(Csla.Core.ChildChangedEventArgs e)

      {

         base.OnChildChanged(e);

      }

   }

   class Program

   {

      static void Main(string[] args)

      {

         PersonList list = new PersonList();

         // this caueses PersonList.OnListChanged to be called one time, as expected

         list.Add(new Person());

         Person bo = list[0];

         // this caueses PersonList.OnChildChanged to be called one time (as expected)

         // and PersonList.OnListChanged to be called two times...?

         bo.FirstName = "Peter";

      }

   }

}   

RockfordLhotka replied on Tuesday, January 20, 2009

Sometimes I get talked into adding features to the framework because they are really good features. And then later I really regret the decision.

The ChildChanged event is a good example, and is the root cause of this issue.

Sometimes when a child object changes, it needs to raise a ListChanged from the parent. Other times it doesn't. Yet always it needs to raise the ChildChanged events all the way to the root. This turns out to be really quite complex.

I thought I had it right, but I am seeing the same issue you are, and it is most certainly because of ChildChanged :(

So, back to the drawing board...

RockfordLhotka replied on Tuesday, January 20, 2009

I believe I've fixed this issue (also noted in other threads), but would appreciate confirmation. You should be able to replace your BLB with the latest code in svn:

http://www.lhotka.net/cslacvs/viewvc.cgi/trunk/cslacs/Csla/BusinessListBase.cs?view=log

And I think it will now work. My unit tests showing double-events and inconsistent behavior before/after serialization are now passing at least.

tetranz replied on Thursday, January 22, 2009

Thanks Rocky. It's working well for me now.

RockfordLhotka:
I believe I've fixed this issue (also noted in other threads), but would appreciate confirmation.

RockfordLhotka replied on Thursday, January 22, 2009

Excellent, thank you!!

 

Rocky

 

From: tetranz [mailto:cslanet@lhotka.net]
Sent: Thursday, January 22, 2009 8:26 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Different ListChanged event behavior in 3.5.2 vs 3.6.0

 

Thanks Rocky. It's working well for me now.

Image removed by sender.RockfordLhotka:

I believe I've fixed this issue (also noted in other threads), but would appreciate confirmation.



Copyright (c) Marimer LLC