Mehfuz's WebLog

Live crazy, think different!

Sponsors

News

Passionate about cutting edge technologies and facinated by the modern web and phone revolution.Currently working at Telerik Corporation, the leading .net component vendor.
Follow me


Articles


Projects

IOrderedQueryable VS IQueryable

We have seen that , while making general LINQ query provider , we have to implement IQueryable along with IQueryProvider.

But what about the following query.

var query = (from ph in context.Photos
             where ph.User == User && ph.PhotoSize == PhotoSize.Medium
 && ph.SearchText == "pocketpc, windows mobile" && 
ph.SearchMode == SearchMode.TagsOnly orderby PhotoOrder.Date_Posted descending
             select ph ).Take(10).Skip(0);

As, this query has orderby clause, this will require IOrderedQueryable instead of IQueryable, or less it will end up with build error.

Now, digging deeper, what is the methodcall for orderby "item" descending/ascending 

Simple order by , like orderby ph.id / orderby ph.id ascending, the internal method call is OrderBy(ph=>ph.id)

Query

var query = from ph in context.Photos where ph.user = "jcl"
 order by ph.Date_Taken select ph;

but if we use, orderby p.id descending , the internal  method call will be made as  OrderByDescending(ph => ph.id).Therefore, in CreateQuery<T>, we have to check for OrderByDescending and OrderBy method separately to process data accordingly.

Which could be

MethodCallExpression curentMethodcall = _expression as MethodCallExpression;

_asc = curentMethodcall.Method.Name == CallType.ORDERBYDESC ? false : true;

ProcessExpression(curentMethodcall.Arguments[1], _dummyPhotoObject);

And during ProcessExpression , the expression breakdown will be

UnaryExpression

    LamdaExpression

        Memberexpresion ( for p = > p.id) or direct ConstantExpression (for p=> "Dake_take")

Source : LinqExtender 

Hope this is useful

kick it on DotNetKicks.com

Posted: Dec 06 2007, 12:27 AM by mehfuzh | with 1 comment(s) |
Filed under: , , ,

Comments

No Comments