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

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

Question

I am trying to write dynamic Linq Library query to fetch record on condition, Customers who has order count is greater than 3 and ShipVia field equal 2.

Below is my syntax what i have tried.

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);

But both are not working. In second query Any returns true so it won't work with Count. Suggest me a way to implement this.

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

Popular Answer

If you HAVE to use Dynamic Linq, your query should look like that:

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