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

Using FilterExpression with Linq queries

5 Answers 425 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 22 Feb 2011, 04:09 PM
Hello!

In my project I need to display employee listing in a hierarchical manner. The amount of data is pretty big to load all records from the data base and takes lots of time, sometimes it gives timeout exception etc. I found a solution to read only top nodes and then, when user expands one of the node, I add ID of the "expanded" employee into a list and then in my query I also check that employee supervisor belongs to this list. This allows to read from the database all top level nodes + children of all expanded nodes.

The problem is, that since I bind a reduced datasource to the grid, built-in filtering/searching mechanism of the grid has no access to the full data and so it doesn't search all employees. Is there a way to use FilterExpression with linq/dynamic linq queries? Or maybe there's some better solution?

Another related question is - is it possible to set ExpandMode per each item and not per TableView? In other words, if a node has been expanded, and child table has been rendered, can I set ExpandMode for this node to be ClientSide, so that there were no postbacks if a user collapses or expands this node again? It's possible for tree-views, if I set

e.Node.ExpandMode =

TreeNodeExpandMode.ClientSide

 

in NodeExpand event handler. But I guess that won't work with the grid, right?

Thank you very much in advance!!!
Andy.

5 Answers, 1 is accepted

Sort by
0
Andy
Top achievements
Rank 1
answered on 22 Feb 2011, 04:27 PM
Regarding the 1st question - as a datasource for the Grid I use DataTable, but it's generated with linq query, which returns reduced amount of data, so it wouldn't help to query DataTable with FilterExpression.
0
Accepted
Iana Tsolova
Telerik team
answered on 25 Feb 2011, 04:20 PM
Hi Andy,

If the grid is bound through its NeedDataSource event, there you should be able to get the generated filter expression add pass it to the method returning the data. Can you check if this works for you?

Regarding your second question: This is not possible with RadGrid. But you can cache the data and on subsequent expands get data from cache instead of querying the database again.

Best wishes,
Iana
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Andy
Top achievements
Rank 1
answered on 28 Feb 2011, 06:10 PM
Hi Iana!

Thanks a lot for your suggestion! Yes, basically, that works, although filter expression can't be used as is, because it uses indexed syntax  (it["Id"] for example) and for Linq queries I need to change it to be it.Id etc. Maybe that's because for the data source I use DataTable, instead of assigning initial IQueryable<T> object ?

Thank you for the help!
Andy.
0
Iana Tsolova
Telerik team
answered on 01 Mar 2011, 01:02 PM
Hi Andy,

You can try binding the grid to IQueryable and see if this works better for your case.
Another option is to disable the grid linq expressions. In this case the filter expressions will use SQL syntax and you might easier translate the expression to linq.

Regards,
Iana
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Andy
Top achievements
Rank 1
answered on 02 Mar 2011, 02:25 PM
Hi Iana!
The problem is that the customer wanted an ability to insert multiple rows, so I use DataTable as a buffer, where I can add new records manually and during databinding set corresponding items into Edit mode. Don't know how this scenario can be performed with IQueryable.

Well, I found more or less acceptable solution to transform filter query, so it works for me now.

Thanks for you help!
Andy.
Tags
Grid
Asked by
Andy
Top achievements
Rank 1
Answers by
Andy
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or