tags:

views:

19

answers:

1

So I have a class is something like this

public class Order
{
    //some other stuff ... 
    //setting the internal _orderItems collection ...
    IEnumerable<OrderItems> OrderItems { get { return _orderItems; }
}

public class OrderItem
{
    //other stuff
    public string ProductName {get; set;}
}

If I have a collection of orders of some sort and have access via linq to the order, something like

 myOrderRespository.Where(x=>x.OrderItems)

Then I only have access to getEnumerator there, waht I would like it to be able to do something like

 myOrderRespository.Where(x=>x.OrderItems.ProductName == "Blah")

Is this possible? this is a made up scenario and its pseudo code I m trying to simplify the problem so its easy to explain ( so please forgive me if there are a few errors) Cheers

+3  A: 

You probably are looking for something like:

var results = myOrderRepository.Where(x => x.OrderItems.Any(item => item.ProductName == "Blah"));

This will return all Order instances with at least one OrderItem that has the ProductName of "Blah".

Reed Copsey
+1 - just beat me to it
Eric Petroelje
thanks, I need to get more linq in my head
Miau