Dynamic Order (SQL ORDERBY) in LINQ CompiledQuery?

I think I found it: Check out this link It will point you to the VS2008 code samples which contains a Dynamic Linq Query Library which contains the extension method below. This will allow you to go: Object. OrderBy("ColumnName") Here is the extension methods, but you may want the whole library public static IQueryable OrderBy(this IQueryable source, string ordering, params object values) { return (IQueryable)OrderBy((IQueryable)source, ordering, values); } public static IQueryable OrderBy(this IQueryable source, string ordering, params object values) { if (source == null) throw new ArgumentNullException("source"); if (ordering == null) throw new ArgumentNullException("ordering"); ParameterExpression parameters = new ParameterExpression { Expression.

Parameter(source. ElementType, "") }; ExpressionParser parser = new ExpressionParser(parameters, ordering, values); IEnumerable orderings = parser.ParseOrdering(); Expression queryExpr = source. Expression; string methodAsc = "OrderBy"; string methodDesc = "OrderByDescending"; foreach (DynamicOrdering o in orderings) { queryExpr = Expression.

Call( typeof(Queryable), o. Ascending? MethodAsc : methodDesc, new Type { source.

ElementType, o.Selector. Type }, queryExpr, Expression. Quote(Expression.

Lambda(o. Selector, parameters))); methodAsc = "ThenBy"; methodDesc = "ThenByDescending"; } return source.Provider. CreateQuery(queryExpr); }.

I think I found it: Check out this link. It will point you to the VS2008 code samples which contains a Dynamic Linq Query Library which contains the extension method below. This will allow you to go: Object.

OrderBy("ColumnName"); Here is the extension methods, but you may want the whole library. Public static IQueryable OrderBy(this IQueryable source, string ordering, params object values) { return (IQueryable)OrderBy((IQueryable)source, ordering, values); } public static IQueryable OrderBy(this IQueryable source, string ordering, params object values) { if (source == null) throw new ArgumentNullException("source"); if (ordering == null) throw new ArgumentNullException("ordering"); ParameterExpression parameters = new ParameterExpression { Expression. Parameter(source.

ElementType, "") }; ExpressionParser parser = new ExpressionParser(parameters, ordering, values); IEnumerable orderings = parser.ParseOrdering(); Expression queryExpr = source. Expression; string methodAsc = "OrderBy"; string methodDesc = "OrderByDescending"; foreach (DynamicOrdering o in orderings) { queryExpr = Expression. Call( typeof(Queryable), o.

Ascending? MethodAsc : methodDesc, new Type { source. ElementType, o.Selector.

Type }, queryExpr, Expression. Quote(Expression. Lambda(o.

Selector, parameters))); methodAsc = "ThenBy"; methodDesc = "ThenByDescending"; } return source.Provider. CreateQuery(queryExpr); }.

2 This can't be compiled though (CompiledQuery.Compile()). – Alex Sep 24 '09 at 6:07.

The in your code where you want your order by string of property name, in this example col1, you just do the following. Hope this helps.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions