How to exclude already selected items from query? RRS feed

  • Question

  • I have an on-line registration form that I developed in the lightswitch HTML client.  It allows students to register for classes.  I have one query, which is all their enrollments in the classes, then another query that shows all available classes.  When a student adds a class to their enrollments, I would like to be able to exclude that class from the list of existing classes.  It should be easy enough since I have the ID's of all the classes in the enrollments, but I can't figure out how to loop through them and turn it into a query that I can append to the Lightswitch query I have written.




    Friday, December 13, 2013 4:25 PM


  • Hi Eric,

    For this scenario we have used pre-process query event to add the used class Id's (custom query like 'ClassesForStudent') to a simple List<> then use !'mylistids'.Contains('class'.Id) added to the query. This is simple and works well for 20 or so Id's. I imagine it does not scale well to hundreds of id's but never tried.

    There are other approaches but this is relatively simple. The technique of building a list of Id's used with custom queries and pre-process events like this is very flexible. You can use any complex logic that you want to construct the list of Id's.


    Dave Baker | AIDE for LightSwitch | Xpert360 blog | twitter : @xpert360 | Xpert360 website | Opinions are my own. For better forums, remember to mark posts as helpful/answer.

    • Edited by Xpert360 Saturday, December 14, 2013 10:30 AM
    • Marked as answer by Angie Xu Tuesday, December 24, 2013 3:10 AM
    Saturday, December 14, 2013 10:30 AM

All replies