This is a migrated thread and some comments may be shown as answers.

Limitations of Where Clauses

1 Answer 85 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
richardFlow
Top achievements
Rank 1
richardFlow asked on 07 Nov 2009, 08:32 PM
Hi,

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?

Thanks,

Richard.
 

1 Answer, 1 is accepted

Sort by
0
Accepted
Damyan Bogoev
Telerik team
answered on 09 Nov 2009, 03:21 PM
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.

Greetings,
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.
Tags
LINQ (LINQ specific questions)
Asked by
richardFlow
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Share this question
or