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

How to filter a navigation property column with ICollection datatype ?

2 Answers 174 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Vu
Top achievements
Rank 1
Vu asked on 12 Dec 2012, 07:24 AM
Hi, I am using RadControls for ASP.NET AJAX Q2 2012 SP1. I am developing an asp.net web page that using RadGrid. I use Entity Framework to get the data from the database. I have 2 entities and the relationship between them is many to many , the below code is for example :
public class User
    {   
        public System.Guid UserId { get; set; }
        public string UserName { get; set; }
 
        public virtual ICollection<Role> Roles { get; set; }
    }
public class Role
    {   
        public System.Guid RoleId { get; set; }
        public string RoleName { get; set; }
     
        public virtual ICollection<User> Users { get; set; }
    }

An user can have many roles and a role can have many users. Then I have a RadGrid that binds a list of User entity to it, I want to filter the RoleName property , for example I want to filter users that have the "Administrator" role name, how can I achieve this ? What I have to to put in "DataField" attribute of that column ? I searched a lot on google and I haven't found any solution for filtering navigation property with ICollection datatype. Please help me
Thank you very much !
Best regards.

2 Answers, 1 is accepted

Sort by
0
Vu
Top achievements
Rank 1
answered on 13 Dec 2012, 04:44 AM
Hi, can anybody help me please ?
0
Eyup
Telerik team
answered on 17 Dec 2012, 07:31 AM
Hello Vu,

Could you please verify that the grid is binded as expected? If so, you could enable grid filtering by enabling the AllowFiltering property, and then set the column's datafield to RoleName:
<telerik:GridBoundColumn ... DataField="RoleName">

Please note that performing complex grid operations such as Inserting, Deleting, Updating, Hierarchy relations, Grouping, Paging, Sorting, Filtering require accommodating appropriate database operations.  Therefore, we suggest you to avoid Simple Databinding and strongly recommend the use of more advanced databinding methods, which automatically handle the aforementioned functions:
Declarative DataSource
Advanced Data Binding

I hope this helps.

Greetings,
Eyup
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
Grid
Asked by
Vu
Top achievements
Rank 1
Answers by
Vu
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or