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

How to filter related child objects ?

4 Answers 203 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stef Heyenrath
Top achievements
Rank 1
Stef Heyenrath asked on 11 Oct 2011, 11:38 AM
I've this Entity :

public class MyEntity
{
    public string Name {get;set;}
}

A simple filter on a Property is defined as follows:
FilterDescriptor filter = new FilterDescriptor();
filter.PropertyName =
"Name";
filter.Operator = FilterOperator.Contains;
filter.Value =
"abc";

and can be accessed using :
query = query.Where(ExpressionBuilder.Expression<MyEntity>(command.FilterDescriptors));


But to define a filter to that I can filter on Child Objects ?
public class MyComplexEntity
{
   
public string Name {get;set;}
   
public IList<OtherEntity> List {get;set;}
}

public class OtherEntity
{
    public string Title {get;set;}
}

FilterDescriptor filter =
new FilterDescriptor();
filter.PropertyName =
"List.Title"; //   ???
filter.Operator = FilterOperator.Contains;
filter.Value =
"xyz";

4 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 11 Oct 2011, 12:01 PM
Hello Stef Heyenrath,

I'm afraid that this is not currently supported. 

Regards,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
dwhite
Top achievements
Rank 1
answered on 09 Jan 2012, 04:09 PM
Has this changed? I have a list of strings. which the grid displays fine (comma-delimited), but I would like the users to be able to filter based on one of the words in the list.

My object is like:

public class Company {
  public string Name { get; set;}
  public List<string> Categories { get; set; }
}

If I enable sorting (e.g. just sort by the comma-delimited string that is displayed) it fails and filtering does as well.

I've tried other strategies like joining a string in the object (read-only property with a string.Join), but that fails because LINQ doesn't know how to use those in a query. I've also tried a string.Join in my LINQ query itself, which fails because string.Join can't be converted to a store function.

Thanks,
-Damien
0
Rosen
Telerik team
answered on 10 Jan 2012, 10:07 AM
Hi,

Unfortunately, this is still not supported. You may consider using custom binding and handle the binding through your own custom routine.

Regards,
Rosen
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Stef Heyenrath
Top achievements
Rank 1
answered on 16 Jan 2012, 01:11 PM
Some things you can do:
1) Use custom binding as described by Rosen.

2) If a company does not have that many categories, you can add this a column to the Company table, like "CompaniesAsCSV".

3) You can build a VIEW which does all the joins and creates a CSV list. (See this)


If you did not need a filter and sort on a CSV list, but just on a string like "Fullname" (which is Firstname + Lastname) you could use Linq.Translations.
Tags
Grid
Asked by
Stef Heyenrath
Top achievements
Rank 1
Answers by
Rosen
Telerik team
dwhite
Top achievements
Rank 1
Stef Heyenrath
Top achievements
Rank 1
Share this question
or