I develop an asp.net solution with Durandal/breeze.
Here is my code to get all my shippers:
var query = EntityQuery.from('Shippers')
.select('id, name, street, city');
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
Here is the related model:
public class Shipper
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public string Street { get; set; }
public string Number { get; set; }
public City City { get; set; }
}
public class City
{
public int Id { get; set; }
public string Name { get; set; }
public string PostCode { get; set; }
public Country Country { get; set; }
}
Now I need to also include countries
public class Country
{
[Key]
public int Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
}
But with the actual query I don't get countries with it.
I try:
var query = EntityQuery.from('Shippers')
.select('id, name, street, city')
.expand('City.Country');
but i get the error:
use of both 'expand' and 'select' in the same query is not currently supported
My question: how to get countries?
UPDATE
As Jay suggested, we can do:
var query = EntityQuery.from('Shippers')
.select('id, name, street, city, city.country')
Now, I got a city_Country
object:
I don't understand why we got this city_Country
because country data are already available in the city \ country object:
Furthermore it gives me problem because my next statement try to map my dto into my entity and this city_Country
object don't exist in my entity and an error occured when mapping.
Below we see my entity object and there are no city_Country
object:
Do I have to do something special on my mapping to avoid it?
Below is my function for the mapping operation:
function mapToEntity(entity, dto) {
// entity is an object with observables
// dto is from json
for (var prop in dto) {
if (dto.hasOwnProperty(prop)) {
entity[prop](dto[prop]);
}
}
return entity;
}