Print Page | Close Window

Include keyword - Get All!

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2159
Printed Date: 04-May-2024 at 6:45pm


Topic: Include keyword - Get All!
Posted By: Jakes
Subject: Include keyword - Get All!
Date Posted: 15-Sep-2010 at 6:38am
I have a query where I use the "Include" keyword to include a navigation property as so:

Address.Include("Cities");

This returns the one city for that address.

My question is, how do I return all the cities as part of a eager load and store it as a property on the Address object. 

I want to use this property to databind a combobox itemssource in a datagrid for user selection.

Thanks in advance.



Replies:
Posted By: sbelini
Date Posted: 16-Sep-2010 at 10:26am

You mention:

"This returns the one city for that address."
 
If there is only one city related to the entities satisfying Address, you will only get one. (Should there be more?)
 
As for your question:
"how do I return all the cities as part of a eager load..."
 
you can use.
 
EntityManager.Cities.Execute();
 
and thereafter refer to a cacheonly query to retrieve the cities. Or even:
 
"and store it as a property on the Address object."
 
not sure what you mean here. Can you clarify?
 
"I want to use this property to databind a combobox itemssource in a datagrid for user selection."
 
var cities = EntityManager.Cities.Execute();
comboBox.ItemSource = cities;
 
I hope this helps.



Print Page | Close Window