我開始爲具有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