【发布时间】:2015-08-05 21:42:10
【问题描述】:
我使用 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
我的问题:如何获取国家/地区?
更新
按照杰的建议,我们可以这样做:
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;
}
【问题讨论】: