tags:

views:

75

answers:

2

I am using Rob's implementation of LazyList and it is working great.

However, I am not able to get a .where clause working on a child entity of the type LazyList.

For eg. something like

var qry = orderRepository.GetOrders();
qry = from p in qry where p.Items.Where(t => t.Name == "test") select p;

produces the following compile time error:

Cannot implicitly convert type 'System.Collections.Generic.IEnumerable<Items>' to 'bool'

What is the correct way to query a child entity?

A: 

Not sure what you are trying to achieve with this statement.

If you want all the orders that have an item with the name "test" then use:

var qry = orderRepository.GetOrders();
qry = from p in qry where p.Items.Any(t => t.Name == "test") select p;

If you want all items that are named "test" then use:

var qry = orderRepository.GetOrders();
qry = from p in qry select p.Items.Where(t => t.Name == "test");
Duke of Muppets
+1  A: 

You need Any.

var qry = orderRepository.GetOrders();
qry = from p in qry where p.Items.Any(t => t.Name == "test") select p;

You already have a where clause, and using a second one won't do any good. The first where (the lowercase one) wants a boolean to be able to perform the filtering, but you are providing an IEnumerable<Items> (because that is what the second .Where returns). Any works the same as Where but returns a boolean whenever there's at least one item that matches the query you specified.

Inferis