我用 Durandal/breeze 开发了一个 asp.net 解决方案。
这是我获取所有托运人的代码:
var query = EntityQuery.from('Shippers')
.select('id, name, street, city');
return manager.executeQuery(query)
.then(querySucceeded)
.fail(queryFailed);
以下是相关模型:
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; }
}
现在我还需要包括国家
public class Country
{
[Key]
public int Id { get; set; }
public string Code { get; set; }
public string Name { get; set; }
}
但是通过实际查询,我没有得到国家。
我尝试:
var query = EntityQuery.from('Shippers')
.select('id, name, street, city')
.expand('City.Country');
但我得到了错误:
use of both 'expand' and 'select' in the same query is not currently supported
我的问题:如何获得国家?
更新
正如 Jay 建议的那样,我们可以这样做:
var query = EntityQuery.from('Shippers')
.select('id, name, street, city, city.country')
现在,我得到了一个city_Country
对象:
我不明白为什么我们得到这个city_Country
,因为城市\国家对象中已经有国家数据:
此外,它给我带来了问题,因为我的下一条语句尝试将我的 dto 映射到我的实体中,并且该city_Country
对象在我的实体中不存在,并且在映射时发生错误。
下面我们看到我的实体对象并且没有city_Country
对象:
我必须在我的映射上做一些特别的事情来避免它吗?
以下是我的映射操作功能:
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;
}