I am trying to create a dynamic query in LinqPad with PredicateBuilder enabled.
First, create a line that matches the where clause for a query like "(orderid> 100 AND customerid <= 100)", and then try to use this line when building a LINQ query with PredicateBuilder. The dynamic query is represented by the variable "dynamicResult" in the code at the end of this message. The query is in the Orders table of the Northwind database in SQL Server 2008 R2.
The query throws this error in LinqPad when I try to execute it:
Cannot implicitly convert type 'string' to 'System.Linq.Expressions.Expression>
Question: How to use a filter that is a string of the type (orderid> 100 AND customerid <= 100) 'with PredicateBuilder? I had "C # Statementments" selected from LinqPad when trying to execute the code below.
I am trying to dynamically build a where clause for a LINQ query.
int? orderParam = 100; string orderOperator = ">="; string linqFilter = ""; linqFilter= String.Format("{0} {1} {2}", "o.OrderID", orderOperator, orderParam); linqFilter.Dump(); var predicate = PredicateBuilder.False<Orders>(); predicate = (linqFilter); var dynamicResult = from o in Orders.Where(predicate) select o; dynamicResult.Dump();
Sunil source share