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

Filter on Navigation Properties (collections)

3 Answers 176 Views
Filter
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 24 Oct 2012, 01:34 PM
Hi,

I'm trying to use the RadFilter control with entities from Entity Framework that have Navigation Properties (collections). The RadFilter works very well on 'normal' Properties (string, int, date, etc.) but I couldn't find a solution for 'enumerable' Properties (list, array, etc.).

For example:
- Entity 'Article' has a navigation property 'Items'
- Entity 'Item' has a property 'Name'

How can i use the RadFilter control to find all 'Articles' with 'Items' that have the property 'Name' set to "whatever"?

Doe's anybody know a solution how to filter these kind of properties?

Regards,
Martin

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 29 Oct 2012, 11:57 AM
Hi,

What kind of datasource you are filtering? Additionally, why you want to place an additional control on the page, while a simple lambda expression will be sufficient?

Please elaborate a bit more about your scenario and if possible share your full page source code along with the code-behind file content. Thus all the people who want to help you will have better understanding of your case.

Kind regards,
Andrey
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 RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Martin
Top achievements
Rank 1
answered on 29 Oct 2012, 03:48 PM
Hi,
So what we try to do is to use the RadFilter control to filter on the items of the articles after the name.

In the markup we have something like this:
<telerik:RadFilter runat="server" ID="filArticles" ShowApplyButton="false" OnPreRender="filArticles_PreRender" ExpressionPreviewPosition="Bottom" Skin="Windows7">
    <ClientSettings>
      <ClientEvents OnFilterCreated="filterCreated" />
    </ClientSettings>
    <FieldEditors>
        <telerik:RadFilterNumericFieldEditor FieldName="Id" DataType="System.Int32" DisplayName="Article id" />
        <telerik:RadFilterTextFieldEditor FieldName="Name" DisplayName="Article name" />
        <telerik:RadFilterTextFieldEditor FieldName="Items.Name" DisplayName="Item name" />
    </FieldEditors>
</telerik:RadFilter>
The code behind would be something like this, just the definition of the data structure for this example:

using System;
using System.Collections.Generic;
using System.Web.UI;
  
namespace WebApplication1
{
         public class Item
         {
                 public int Id { get; set; }
                 public string Name { get; set; }
         }
  
         public class Article
         {
                 public int Id { get; set; }
                 public string Name { get; set; }
                 public List<Item> Items { get; set; }
         }
  
         public partial class Default : Page
         {
                 protected void Page_Load(object sender, EventArgs e)
                 {
                          var source = new List<Article>();
  
                          source.AddRange(
                                   new List<Article>()
                                            {
                                                    new Article
                                                             {
                                                                      Id = 1,
                                                                      Name = "Article a",
                                                                      Items = new List<Item> {new Item {Id = 1, Name = "Item 1"}, new Item {Id = 2, Name = "Item 2"}}
                                                             },
                                                    new Article
                                                             {
                                                                      Id = 2,
                                                                      Name = "Article b",
                                                                      Items = new List<Item> {new Item {Id = 1, Name = "Item 1"}, new Item {Id = 2, Name = "Item 2"}, new Item {Id = 3, Name = "Item 3"}}
                                                             },
                                                    new Article
                                                             {
                                                                      Id = 2,
                                                                      Name = "Article c",
                                                                      Items = new List<Item> {new Item {Id = 1, Name = "Item 1"}, new Item {Id = 2, Name = "Item 3"}, new Item {Id = 4, Name = "Item 4"}}
                                                             }
                                            });
                 }
         }
}
And here is how we build the query, in our project we try to get the data via entity framework.
It works for all ‘normal’ properties (like article name) but not for ‘enumerable’ properties (like item name): 

var articleManager = ManagerFactory.GetManager<ArticleManager>();
var provider = new RadFilterEntitySqlQueryProvider();
provider.ProcessGroup(expressionRoot);
var expression = provider.Result;
var query = ((ObjectQuery<Item>)ObjectSet).OfType<Article>().Where(expression);
For example, we want to filter after “Item1” and get all the articles back which have an item named “Item1”.
In this example this would be all articles. For “Item3” we expect to get back “Article b” and “Article c”.
Regards,
Martin
0
Andrey
Telerik team
answered on 01 Nov 2012, 01:24 PM
Hi,

Based on the provided code I was not able to make a runnable project for testing. Could you open a formal support ticket in which to attach a runnable sample project that replicates the issue? Thus we will be able to test/debug the project locally and let you know what is the problem.

Regards,
Andrey
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 RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Filter
Asked by
Martin
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Martin
Top achievements
Rank 1
Share this question
or