Print Page | Close Window

Querying through Multiple Levels

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2136
Printed Date: 10-Jun-2026 at 7:09pm


Topic: Querying through Multiple Levels
Posted By: benmcneill
Subject: Querying through Multiple Levels
Date Posted: 09-Sep-2010 at 2:56am
Hi Guys

Have been searching through the documentation but having trouble figuring this one out.

I have a Master table, say 'Baskets'. There is a many-to-many relationship to a Detail table 'Fruits'. Ie, Many Fruits exist in many Baskets. There is a field/property on the Fruits table called 'Color'.

What I want to do is get ALL Baskets that contain any fruit of color 'Red'.

What I want is something like:

EntityQuery<Baskets> query = mgr.Baskets.Where(p => p.Fruits.Color == 'Red')

However, the 'Color' property doesn't appear in the intellisense list after 'p => p.Fruits.' Instead, I only get a bunch of methods (eg p.Fruits.Single() or p.Fruits.Contains() instead of what I want which is p.Color). What am I missing here?

Thanks in advance,
Ben





Replies:
Posted By: sbelini
Date Posted: 09-Sep-2010 at 5:19pm
Hi Ben,
 
try:
 
var query = mgr.Fruits.Where(f => f.Color == "Red").Select(f => f.Baskets);
 
Regards,
   Silvio.


Posted By: benmcneill
Date Posted: 09-Sep-2010 at 5:32pm
Hi Silvio

That worked! Thanks for your help, much appreciated.

Regards,
Ben



Print Page | Close Window