Limitations of Where Clauses

2 posts, 1 answers
  1. richardFlow
    richardFlow avatar
    62 posts
    Member since:
    Jun 2012

    Posted 07 Nov 2009 Link to this post


    I build up a conditional linq statement based on input from a webpage.  All works fine until i try and add both the following conditions simulatenously, at which point the webpage crashes the visual studio webserver everytime i try and run it.

    the filters look as follows:

    //filter 1:
     if (InWebsiteUid != null) list = list.Where(x => x.Product.ProductCategories.Any(y => y.Category.CategoryTree.Websites.Any(z => z.Uid == InWebsiteUid)));
    //filter 2:
     if (NotInWebsiteUid != null) list = list.Where(x => !x.Product.ProductCategories.Any(y => y.Category.CategoryTree.Websites.Any(z => z.Uid == NotInWebsiteUid)));

    Either one of the filters works fine, but when i try both together it crashes immediately.

    Any suggestions?


  2. Answer
    Damyan Bogoev
    Damyan Bogoev avatar
    581 posts

    Posted 09 Nov 2009 Link to this post

    Hi Web Belief Ltd,

    Unfortunately we were not able to reproduce the problem. We used the Northwind database and the following code in order to represent the behavior:
    string inCountry = "USA";
    string notInCountry = "France";
    IEnumerable<Customer> list = scope.Extent<Customer>();
    if (inCountry != null)
        list = list.Where(
            c => c.Orders.Any(o => o.OrderDetails.Any(od => od.Order.ShipCountry == inCountry))
    if (notInCountry != null)
        list = list.Where(
            c => !c.Orders.Any(o => o.OrderDetails.Any(od => od.Order.ShipCountry == notInCountry))

    At this stage we will have to ask you to provide us with some additional information. Can you please share some more details regarding the classes in the project? It will be great if you can send us the exception and the stack trace as well.
    We are looking forward to your reply.

    Damyan Bogoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
Back to Top