Filter on Navigation Properties (collections)

4 posts, 0 answers
  1. Martin
    Martin avatar
    2 posts
    Member since:
    Jul 2011

    Posted 24 Oct 2012 Link to this post

    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
  2. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 29 Oct 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Martin
    Martin avatar
    2 posts
    Member since:
    Jul 2011

    Posted 29 Oct 2012 Link to this post

    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
  5. Andrey
    Admin
    Andrey avatar
    836 posts

    Posted 01 Nov 2012 Link to this post

    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.
Back to Top