In Dynamic Linq, use Any() and Count().

asp.net c# dynamic-linq linq linq-to-sql

Question

I'm attempting to create a dynamic Linq Library query to get data based on the following criteria: Customers with an order quantity larger than three and a ShipVia field equal to two.

Here is my tried-and-true syntax.

object[] objArr = new object[10];
objArr[0] = 1;
IQueryable<Customer> test = db.Customers.Where("Orders.Count(ShipVia=2)", objArr);

and

IQueryable<Customer> test = db.Customers.Where("Orders.Any(ShipVia=2).Count()", objArr);

Both, however, are ineffective. Any returns true in the second question, hence it is incompatible with Count. Tell me how I can put this into practice.

1
2
6/29/2011 2:26:04 PM

Popular Answer

The following is how your query should seem if you HAVE to use Dynamic Linq:

db.Customers.Where("Orders.Count(ShipVia == 2) > 3");
2
1/31/2014 8:27:48 AM


Related Questions





Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow