QCV - "any" filter on child entities

2 posts, 1 answers
  1. Heiko
    Heiko avatar
    134 posts
    Member since:
    Oct 2012

    Posted 10 Oct 2014 Link to this post

    I have a list of customers, and each customer itself has a list of contacts. To check if either the customer or a contact contains a certain name I would do the following query (in Entity Framework and LINQ):

            (cust => cust.Name.Contains(filter) ||
            cust.Contacts.Any(contact => contact.LastName.Contains(filter)));

    Which means: look inside the customer.Name or every contact belonging to the customer and look inside contact.LastName if it contains the filter-string.

    Big question: how can this be done by creating a (Composite-) FilterDescriptor so that a QueryableCollectionView gets filtered correctly? First part is easy, but the second part "cust.Contacts.Any(...)" makes me a headache.

  2. Answer
    Dimitrina avatar
    3769 posts

    Posted 13 Oct 2014 Link to this post

    Hello Neils,

    In your case you would like to apply filtering criteria on the Member Contacts based also on a criteria on the contacts. To so do you should specify the Member of the descriptor to be Contacts. Then, I am afraid there is not a Filtering operator like Any or Exists that filters entire collection, you can filter data fields by a specific value. You can find information on all the available filtering operators here.

    In that case, I can suggest you adding a generic filter descriptor (FilterDescriptor<T>) to build the proper LINQ query to filter on manually.

    You can check the Use generic FilterDescriptor documentation for an example on how to do so.


    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top