How I can call this LinqKit expression
public static Expression<Func<Transaction, string>> ExpressionOfStatusName
{
get
{
Expression<Func<Transaction, string>> status =
(transaction) => transaction.TransactionStatus.Name;
return status;
}
}
in a dynamic linq query (Linq as a string using System.Linq.Dynamic from Microsoft)
This expression works well in a standard Linq query like this
Expression<Func<Transaction, string>> expressionOfStatusName = Transaction.ExpressionOfStatusName;
var ex = from transaction in context.Transaction.AsExpandable()
select expressionOfStatusName.Invoke(transaction)
But when I try to call it from a dynamic linq query, I receive an error "No applicable method 'Invoke' exists in type 'Expression`1' I have tried to add the linqkit import in the file System.Linq.Dynamic but it is still not working.
I want to be able to do something like that
var ex = context.Transaction.AsExpandable()
.Select (transaction=>transaction)
.Select("new { test = expressionOfStatusName.Invoke(transaction)");
Thank you for your help
Linq expects Expression of func. You can use the MS Linq.Dynamic extension which takes strings and converts them to an Expression tree. Or you can use any tool you like to build the expression tree. The MS dynamic linq extension however parses a limited set of String inputs. Some sample docu/blog You are asking it to parse expressionOfStatusName.Invoke(transaction)" I dont think it can do that. You can debug the source to check. But i recall seeing simple membership analysis in there. The source is here
Furthermore I think you are pushing the limits on acceptable anonymous type input, once you get passed the parse challenge. anonymous types and Linq