I am missing a key piece of understanding in my first attempt to pull full entity graphs for an entity with Breeze and EF6 (Hottowel/John Papa flavor)
I have a parent-child-grandchild relationship of Policies-P_Locations-P_Hazards
I want to see the graphs for all policies for one client
In short my query returns the JSON shaped at I expect (confirmed in XHR viewer) and the data.results allow me to drill down (through backingstore - man do we need a viewer on the javascript like C#) to see arrays for children and grandchildren. I see all the policies, locations and hazards I expect for the client (dll version and model/modelmap code at the end of post)
datacontext:
function getPoliciesByClientsId(clientsid) {
var policies;
return EntityQuery.from('Policies')
.withParameters({ clientsid: clientsid })
.expand('P_Locations, P_Locations.P_Hazards')
.using(manager).execute()
.then(querySucceeded, _queryFailed);
function querySucceeded(data) {
policies = data.results;
log('Retrieved [Policy] from remote data source', policies.length, true);
return policies;
}
}
controller :
function getPoliciesByClientsId(clientsid) {
return datacontext.getPoliciesByClientsId(clientsid).then(function(data) {
vm.Policies = [];
vm.Policies = data;
// at this point vm.Policies shows an object array
// and I can see p_Locations for each policy and p_Hazards for each location
// but vm.Policies.p_locations is undefined
return vm.Policies;
}
);
}
If I drill into policies in datacontext or vm.Policies in controller I see the camel cased arrays.
BUT
vm.Policies.p_Locations is undefined. And of course I want to reference vm.Policies.p_Locations.p_Hazards as well.
What am I missing in order to reference the graph of data for binding?
BreezeController:
[HttpGet]
public IQueryable<Policy> Policies()
{
return _repository.Policies;
}
PwiRepository
public IQueryable<Policy> Policies
{
get { return Context.Policies; }
}
And that creates this request :
Request URL:http://localhost:29130/breeze/Breeze/Policies?$expand=P_Locations%2CP_Locations%2FP_Hazards&clients_id=439
Using manager.metadataStore.getEntityType('P_Location') and then drilling to navigation properties I find these
navigationProperties: Array[4]0:
dassociationName: "P_Hazard_P_Location"
entityType: l
entityTypeName: "P_Hazard:#Pwi.Model.Models"
foreignKeyNames: Array[0]
foreignKeyNamesOnServer: Array[0]
invForeignKeyNames: Array[1]
invForeignKeyNamesOnServer: Array[1]
inverse: disScalar: falsename: "p_Hazards"
nameOnServer: "P_Hazards"
parentType: lvalidators: Array[0]
associationName: "P_Location_Policy"
entityType: lentityTypeName: "Policy:#Pwi.Model.Models"
foreignKeyNames: Array[1]
foreignKeyNamesOnServer: Array[1]
invForeignKeyNames: Array[0]
invForeignKeyNamesOnServer: Array[0]
inverse: disScalar: truename: "policy"
nameOnServer: "Policy"parentType: l
relatedDataProperties: Array[1]validators: Array[0]__proto__: Objectlength: 4
Here are the dll pieces
<packages>
<package id="Breeze.Server.ContextProvider" version="1.4.17" targetFramework="net45" />
<package id="Breeze.Server.ContextProvider.EF6" version="1.4.17" targetFramework="net45" />
<package id="Breeze.Server.WebApi2" version="1.4.17" targetFramework="net45" />
<package id="EntityFramework" version="6.1.1" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.OData" version="5.2.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.0" targetFramework="net45" />
<package id="Microsoft.Data.Edm" version="5.6.2" targetFramework="net45" />
<package id="Microsoft.Data.OData" version="5.6.2" targetFramework="net45" />
<package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.4.0" targetFramework="net45" />
<package id="System.Spatial" version="5.6.2" targetFramework="net45" />
<package id="WebActivator" version="1.5.3" targetFramework="net45" />
</packages>
I have a parent-child-grandchild relationship of Policies-P_Locations-P_Hazards Here are the relevant parts of the model and model mapping
P_Location Model :
public partial class P_Location
{
public P_Location()
{
this.P_GlCoverages = new List<P_GlCoverage>();
this.P_Hazards = new List<P_Hazard>();
this.P_PropertyCoverages = new List<P_PropertyCoverage>();
}
public int P_Locations_id { get; set; }
public int Policies_id { get; set; }
......
public virtual Policy Policy { get; set; }
public virtual ICollection<P_Hazard> P_Hazards { get; set; }
P_LocationMap
// Relationships
this.HasRequired(t => t.Policy)
.WithMany(t => t.P_Locations)
.HasForeignKey(d => d.Policies_id);
P_Hazard Model
public Policy Policy { get; set; }
public P_Location P_Location { get; set; }
P_HazardMap
// Relationships
this.HasRequired(t => t.P_Location)
.WithMany(t => t.P_Hazards)
.HasForeignKey(d => d.P_Locations_id);