Problem with OnFieldChanged() event

Posts   
 
    
Jeff M
User
Posts: 250
Joined: 04-Aug-2004
# Posted on: 19-Jul-2005 05:32:58   

Hello all. Using adapter:

I use the OnFieldChanged() event on a field to populate a DataSource as follows:

public CatalogueDetailForm(EntityBase2 entity)
            : base ()
        {   
            EntityBase2 Entity = entry ;
            InitializeComponent();
.....

            ((CatalogueDetailEntity)Entity).CatDetailCategoryKeyChanged += new EventHandler(KeyChanged);
        }

void KeyChanged(object sender, EventArgs e)
        {
            bindingSourceSubCategories.DataSource = ReferencesManager.GetCatalogueDetailSubCategoryList
                (((CatalogueDetailEntity)Entity).CatDetailCategoryKey) ;
        }
.....

Problem is, for whatever reason the KeyChanged delegate gets triggered several times when there's a simple change to the CatDetailCategoryKey value. Sometimes it gets triggered seven or eight times after a chane to CatDetailCategoryKey. Obviously, this creates a bottleneck since GetCatalogueDetailSubCategoryList makes a server call each time.

I'm aware that OnFieldChanged() events are used internally by LLBLGen. I haven't really dug deep into code to determine why this problem is happening but I'm wondering if its just not a good idea to use the OnFieldChanged() in this way.

Thanks.

Jeff

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 19-Jul-2005 11:46:35   

The event is fired when the field is actually changed (duh wink ) but only then. The OnfieldChanged event is only called frm the properties.

Could you set a breakpoint in the OnfieldChanged() method in the entity, please? And check at runtime each time what the stacktrace (when the breakpoint hits) to see where the call comes from?

Frans Bouma | Lead developer LLBLGen Pro
Jeff M
User
Posts: 250
Joined: 04-Aug-2004
# Posted on: 19-Jul-2005 15:23:28   

Will do.