Include() Question
-
I want to include data from a foreign key table to one of my foreign key tables. How do I accomplish this? Example: This query returns all of my observations, Observation has a foreign key relationship to Property.
return this.ObjectContext.Observations.Include("Defect").Include("Property").Include("Location");
This query returns all properties, separate of Observation:
return this.ObjectContext.Properties.Include("StreetSuffix");
The issue is that I want to include "StreetSuffix" in the first query so that I can access the street suffix name from the datagrid that is populated by the top query. The streetsuffix is related to observation through property. Cheers, --EA
-
I want to include data from a foreign key table to one of my foreign key tables. How do I accomplish this? Example: This query returns all of my observations, Observation has a foreign key relationship to Property.
return this.ObjectContext.Observations.Include("Defect").Include("Property").Include("Location");
This query returns all properties, separate of Observation:
return this.ObjectContext.Properties.Include("StreetSuffix");
The issue is that I want to include "StreetSuffix" in the first query so that I can access the street suffix name from the datagrid that is populated by the top query. The streetsuffix is related to observation through property. Cheers, --EA
Just add StreetSuffix in the Property include
return this.ObjectContext.Observations.Include("Property.StreetSuffix")
Also check this blog post for a Include using lamba expression: Improving Objectquery-lt-t-gt-include[^] Be careful with Include as the resulting query can become quite complex. Sometime it can be more efficient to do multiple simple query.
Vince Remember the dead, fight for the living