From: fiza on
I need to build a form that will take in string value from dropdowns
for:
sort_colum_name,
search_column_name,
table_name
and textbox for search_text

I know this is possible using expression trees, but somehow cant form
the statements. Please help
Here's what I have so far:

private static List<T> GetSortedData<T>( string sortColumnName)
{


var type = typeof(T);
var property = type.GetProperty(sortColumnName);
var parameter = Expression.Parameter(type, "p");
var propertyAccess =
Expression.MakeMemberAccess(parameter, property);
var orderByExp = Expression.Lambda(propertyAccess,
parameter);

MethodCallExpression resultExp =
Expression.Call(typeof(Queryable), "OrderBy", new Type[] { type,
property.PropertyType }, WHAT_SHOULD_BE_HERE,
Expression.Quote(orderByExp));

return
(List<T>)Expression.Lambda(resultExp).Compile().DynamicInvoke();
}
From: Peter Duniho on
fiza wrote:
> I need to build a form that will take in string value from dropdowns
> for:
> sort_colum_name,
> search_column_name,
> table_name
> and textbox for search_text
>
> I know this is possible using expression trees, but somehow cant form
> the statements. Please help [...]

Why do you want to use expression trees? Why not just write a LINQ
expression that incorporates the values from your dropdowns as
appropriate for the operation (search or sort)?

Pete
From: fiza on

> Why do you want to use expression trees?  Why not just write LINQ
The form shall draw data from many tables. I want to avoid writing the
sort and search for every field for each of the tables. This is why I
want to use Expression trees. I want to build the query dynamically