我开始为具有Web API 2.1后端的项目使用breezejs。我有一个名为Country的实体,它具有一个名为Continent的实体的外键/导航属性。 我想使用国家作为查找值,但我也需要他们与大洲的关系,所以我也想获取这些信息。带导航属性的BreezeJS查找
public class Country
{
public string Iso { get; set; }
public string Name { get; set; }
public virtual Continent Continent { get; set; }
}
我也有一个名为continentIso的FK字段,但我没有在代码中使用它。
目前后端控制器的样子:
[HttpGet]
public object Lookups() {
var countries = _breezeRepository.Get<Country>().Include(it=>it.continent);
//more lookups in here
return new { countries };
}
由于每breeze samples我返回实体的匿名对象(我有一对夫妇更但是从上面取出来,以避免混淆)。
在前端侧我有一个查找资料库(由约翰·爸爸的Building Apps with Angular and Breeze - Part 2证明):
function setLookups() {
this.lookupCachedData = {
countries: this._getAllLocal(entityNames.country, 'name'),
};
}
问题是,虽然发送的JSON包含大陆值,国家对象不包含值或它们的导航属性。 我也试过把各大洲作为一个独立的查询,并尝试通过微风元数据扩展来加入它们,就像我将查找与实体连接一样,但无济于事。
我认为模型本身并不需要FK,但只在实体映射中,但我想这不是这种情况。我已经添加了密钥,现在它可以与Include一起使用。 – masimplo