This question is locked. New answers and comments are not allowed.
I have a Linq Query stored in session and bound to a gridview like this:
Each Time a user clicks a column header, I would like to sort the query. This would be the normal way I would do it if it was a dataTable stored in session:
What is the alternative way to make this work with LINQ?
Code: |
gvResults.DataSource = persons
gvResults.DataBind() Session("PERSONS") = persons |
Each Time a user clicks a column header, I would like to sort the query. This would be the normal way I would do it if it was a dataTable stored in session:
Code: |
Dim dt As DataTable = Session("PERSONS") Dim dv As DataView = New DataView(dt) dv.Sort = sortEx 'Save back to Session so paging functionality remains Session("PERSONS") = dv.ToTable() gvResults.DataSource = Session("PERSONS") gvResults.DataBind() |
What is the alternative way to make this work with LINQ?
7 Answers, 1 is accepted
0
Hello Michael,
in the sorting event of the grid you can do a query similar to this one:
Please do not hesitate to contact us if you face any further difficulties.
Kind regards,
PetarP
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
in the sorting event of the grid you can do a query similar to this one:
IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope(); |
IQueryable<Offer> result = from c in scope.Extent<Offer>() |
.OrderBy(e.SortExpression.ToString()) |
select c; |
GridView1.DataSource = result.ToList(); |
GridView1.DataBind(); |
Kind regards,
PetarP
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Jay
Top achievements
Rank 1
answered on 15 Feb 2010, 05:20 PM
I'm using Q3 2009 SP 1 and this syntax won't compile. I can use a function parameter so that it looks like
from a in Scope.Extent<T>().OrderBy(order => "Id") |
select a; |
but this produces the following runtime error.
Unable to cast object of type 'Telerik.OpenAccess.Query.Context' to type 'OpenAccessRuntime.DataObjects.query.Node'.
What's going on? What am I doing wrong?
0
Hello Jay,
You should slightly modify the binding query in the following way:
I think that will help you.
All the best,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
You should slightly modify the binding query in the following way:
from a
in
Scope.Extent<T>().OrderBy(order => order.Id) select a;
I think that will help you.
All the best,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jay
Top achievements
Rank 1
answered on 17 Feb 2010, 10:37 PM
Unfortunately that doesn't allow me to do what I want to do -- which is to sort dynamically.
0
Hello Jay,
Unfortunately at the moment Telerik OpenAccess ORM does not support dynamic expressions inside an OrderBy clause. This functionality is on our to-do list and will be part of the product in the future.
Your current option is to use the solution provided by Petar and pass the SortExpression to the OrderBy clause.
Greetings,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Unfortunately at the moment Telerik OpenAccess ORM does not support dynamic expressions inside an OrderBy clause. This functionality is on our to-do list and will be part of the product in the future.
Your current option is to use the solution provided by Petar and pass the SortExpression to the OrderBy clause.
Greetings,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jay
Top achievements
Rank 1
answered on 13 Sep 2010, 10:19 PM
Any update on the dynamic expressions inside the order by clause? Is this featured getting any closer to being implemented?
0
Hello Jay,
You could try this code library example. It demonstrates how to use OpenAccess with Dynamic Linq. Additional useful information with regard to Dynamic Linq and OpenAccess can be found here.
Hope that helps.
Greetings,
Damyan Bogoev
the Telerik team
You could try this code library example. It demonstrates how to use OpenAccess with Dynamic Linq. Additional useful information with regard to Dynamic Linq and OpenAccess can be found here.
Hope that helps.
Greetings,
Damyan Bogoev
the Telerik team
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Public Issue Tracking
system and vote to affect the priority of the items