Reputation: 4298
I’m using WebAPI V4.0.30506.0 (this should be the stable version) with BreezeJs 1.3.5 and for some reason I don’t get child entities when I use the expand keyword. How can I get the child entities?
Here’s a cut down version of my datamodel.
public class Policy
{
public int Id { get; set; }
public string PolicyNumber { get; set; }
public ICollection<Vehicle> Vehicles { get; set; }
}
public class Vehicle
{
public int Id { get; set; }
public string Manufacturer { get; set; }
public string Model { get; set; }
public int ModelYear { get; set; }
public virtual Policy Policy { get; set; }
}
Here’s what my get looks like:
var getPolicies = function (policyObservable, getFromServer) {
if (!getFromServer) {
var pLocal = getLocal('Policies', 'policyNumber');
if (pLocal.length > 0 ){
policyObservable(pLocal);
return Q.resolve();
}
}
var query = EntityQuery.from('Policies')
.expand("Vehicles");
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
// handle the ajax callback
function querySucceeded(data) {
if (policyObservable) {
// I pause here in Chrome
policyObservable(data.results);
}
log('retrieved policy!', data, true);
}
};
When I look at the data.results in querySucceeded in Chrome I see an array of Policies but there are no child vehicles. When I check in the network tab I see it calling:
http://localhost/breeze/breeze/Policies?$expand=Vehicles
And there are Vehicles in the results.
Here’s a snippet of what I get back:
[ { "$id": "1", "$type": "Eclipse.Model.Policy, Eclipse.Model", "Id": 1, "PolicyNumber": "PHHOAP00", "Vehicles": [ { "$id": "2", "$type": "Eclipse.Model.Vehicle, Eclipse.Model", "Id": 1, "Manufacturer": "ac,", "Model": "In", "ModelYear": 2006, "Policy": { "$ref": "1" },...
edit: I'm not sure if it's related or not but when I type the following in the console I get blank arrays.
console.log(data.results[0].entityAspect._entityKey.entityType.navigationProperties)
console.log(data.results[0].entityAspect._entityKey.entityType.foreignKeyProperties)
Upvotes: 0
Views: 481
Reputation: 4298
Reverting to the 1.3.4 version of breeze.debug.js fixed the issue.
In my case it appears that in 1.3.5 OData $expand doesn't map properly to the data.results.
Upvotes: 0
Reputation: 526
Maleki, Have you tried adding a ForeignKey to the Policy in Vehicle? Breeze will need the FK to resolve the navigation between entities and this is most likely what's causing the problem.
Upvotes: 1