THESE FORUMS ARE NOW FROZEN
Please choose "Forums" from the Main menu of www.entityspaces.net to get to our new forums.

How to 'unhook' a query from the collection?

rated by 0 users
This post has 3 Replies | 1 Follower

Top 50 Contributor
Posts 64
leonidbogdanov Posted: 03-07-2008 5:14 PM

Here is the problem... I load a collection using collection1.Load(query) call, then change the query,  create another collection and load the second collection with the modified query: collection2.Load(query). The second call removes data from the collection1 and populates both collections with data from the second Load() call.

I think the problem is in the HookupQuery/InityQuery pair inside the generated collection class. These methods hookup the event handler to the query:

query.OnLoadEvent += new esDynamicQuery.QueryLoadedDelegate(OnQueryLoaded);

but never remove the event handler. This code shoul be better changed to disconnect the event before attaching it:

query.OnLoadEvent -= new esDynamicQuery.QueryLoadedDelegate(OnQueryLoaded);

query.OnLoadEvent += new esDynamicQuery.QueryLoadedDelegate(OnQueryLoaded);

 Is there a workaround for this problem or should I recreate a query for the second call?

 Thanks,

Leonid

Top 10 Contributor
Posts 3,881
Good catch, you are right, for now you will need to use a 2nd query, however, you could tweak the template and regenerate. Let me get this fix into ES2008 then show you the fix, it will be something you can add to your templates and then just regenerate.  Thank you.

EntitySpaces | Twitter | BLOG | Please honor our Software License

Top 50 Contributor
Posts 64

Thank you Mike.

Just one more thought. Probably it's a good idea to implement IDisposable interface in ES classes. Then the event handler can be also released inside the Dispose method, so the collection can be removed from memory without disposing the query.

Leonid

Top 10 Contributor
Posts 3,881
The event handler is now cleared, even in the event of an exception, this will be in our next ES2008 Beta.

EntitySpaces | Twitter | BLOG | Please honor our Software License

Page 1 of 1 (4 items) | RSS
Copyright © 2005 - 2009, EntitySpaces, LLC