Use Any() and Count() in Dynamic Linq

Posted by ArpanDesai on Stack Overflow See other posts from Stack Overflow or by ArpanDesai
Published on 2011-06-29T14:24:44Z Indexed on 2011/06/29 16:22 UTC
Read the original article Hit count: 510

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET