I create a dynamic expression that will order the elements in the list according to some rule (lambda exp.). This is the code:
Expression<Func<String, String>> exp = o => o;
MethodCallExpression orderByExp = Expression.Call(typeof(Enumerable), "OrderBy",
new Type[] { typeof(String), exp.Body.Type }, Expression.Parameter(typeof(IEnumerable<String>), "list"), exp);
Now I want to execute the previously created expression for specific data to sort it, but it does not work due to some strange exceptions, such as "Lambda Parameter not in scope" or "Argument expression is not valid".
var data = new String[] { "asdasdasd", "asdads", "123", "xcvxcvs", "ASDSD" };
var result = data.AsQueryable().Provider.CreateQuery<String>(orderByExp);
Can someone help me with this?
source
share