The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

How to 'unhook' a query from the collection?

Last post 05-03-2008, 2:07 PM by Mike.Griffin. 3 replies.
Sort Posts: Previous Next
  •  03-07-2008, 5:14 PM 8325

    How to 'unhook' a query from the collection?

    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

  •  03-10-2008, 4:41 AM 8353 in reply to 8325

    Re: How to 'unhook' a query from the collection?

    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
  •  03-10-2008, 8:06 AM 8355 in reply to 8353

    Re: How to 'unhook' a query from the collection?

    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

  •  05-03-2008, 2:07 PM 9175 in reply to 8355

    Re: How to 'unhook' a query from the collection?

    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
View as RSS news feed in XML