How to make order by Column variable because I have a dropdown on page and I want to show grid according to sord order selected in this Dropdown e.g Price, Code, rating, description etc etc. and I donot want to write a separate query for each column.
from lm in lDc.tbl_Products
where lm.TypeRef == pTypeId
orderby lm.Code ascending
select new;
You can "build up" a LINQ query in separate steps.
Generate your base query to return the information unsorted. This query will not be executed until you try and enumerate the results.
Then in your event handler, apply whatever sorting you wish before binding the results to the grid.
The full query you enumerate over is the one which will be evaluated. This means you can run a separate query for each item in your drop down, built from a "base" query.
Usage:
Assuming you want to do the sorting via SQL then you will need to pass in the sort column/type. The query is deferred until you actually do the select so you can build up the query in steps and once you are done execute it like so:
If you want to do it outside of SQL then just get a basic result with no sorting and then apply an OrderBy to the result base on the sort criteria you need.