Dynamic LINQ – Is There A .NET 4 Version?
You may want to take a look at PredicateBuilder
You may want to take a look at PredicateBuilder
This may not be the best/most efficient method, but it does work. Expression<Func<Product, bool>> exp = (x) => (x.Id > 5 && x.Warranty != false); string expBody = ((LambdaExpression)exp).Body.ToString(); // Gives: ((x.Id > 5) AndAlso (x.Warranty != False)) var paramName = exp.Parameters[0].Name; var paramTypeName = exp.Parameters[0].Type.Name; // You could easily add “OrElse” and others… expBody … Read more
Well, I do not agree that the injection is not possible in Dynamic Linq. What described in the answer by Ɖiamond ǤeezeƦ is correct but appies to standard Linq as constructed within the given language – C# or VB.Net or by calling extension methods like .Where with lambda functions. Then, true, it is not possible … Read more
You can do this by dynamically creating the lambda you pass to Select: Func<Data,Data> CreateNewStatement( string fields ) { // input parameter “o” var xParameter = Expression.Parameter( typeof( Data ), “o” ); // new statement “new Data()” var xNew = Expression.New( typeof( Data ) ); // create initializers var bindings = fields.Split( ‘,’ ).Select( o … Read more