LinqFu: Linq in Linq (part 1 of n)

I had to perform some LinqFu today where I used a Linq expression within a Linq expression and thought I would post a reminder to myself about what I did and how I did it. Looking at it afterward, I’m surprised it was as simple as it was. *shrug* I guess that’s how these things go.
 
Basically, it’s the equivalent of selecting an order based on its order items (to use the classic relationship scenario).
 
var value = 10;
 
if ((from order in orders where order.Items.Any(item => item.Value >= value) select order).Any()) { //Any orders w/item whose value is >= value
   MessageBox.Show(string.Format("There are orders with items greater than or equal to ‘{0}’, value));
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s