This is a migrated thread and some comments may be shown as answers.

QCV - "any" filter on child entities

1 Answer 45 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Heiko
Top achievements
Rank 1
Iron
Veteran
Heiko asked on 10 Oct 2014, 02:26 PM
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):

query.Where
        (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.

Regards
Neils

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 13 Oct 2014, 10:35 AM
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.


Regards,
Dimitrina
Telerik
 

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.

 
Tags
General Discussions
Asked by
Heiko
Top achievements
Rank 1
Iron
Veteran
Answers by
Dimitrina
Telerik team
Share this question
or