Reputation: 3774
I am starting to use breezejs for a project with a Web API 2.1 backend. I have an entity called Country that has a foreign key/navigation property to an entity called Continent. I want to use the countries as lookup values but I also need their relationship to continents so I would like to fetch that info as well.
public class Country
{
public string Iso { get; set; }
public string Name { get; set; }
public virtual Continent Continent { get; set; }
}
I also have a FK field called continentIso but I don't use it in code.
Currently the backend controller looks like:
[HttpGet]
public object Lookups() {
var countries = _breezeRepository.Get<Country>().Include(it=>it.continent);
//more lookups in here
return new { countries };
}
As per the breeze samples I am returning an anonymous object of entities (I have a couple more but removed them from the above to avoid confusion).
On the front end side I have a lookup repository (demonstrated by John Papa's Building Apps with Angular and Breeze - Part 2):
function setLookups() {
this.lookupCachedData = {
countries: this._getAllLocal(entityNames.country, 'name'),
};
}
Problem is that although the sent JSON contains values for the continents, the countries object does not contain a value or a navigation property for them. I have also tried bringing the continents as a separate lookup and try joining them through breeze metadata extension as I do for connecting lookups with entities but to no avail.
Upvotes: 2
Views: 251
Reputation: 4489
I also have a FK field called continentIso but I don't use it in code.
Probably that's the problem as explained here.
I would try the followings:
Make sure you have the Continent FK explicitly defined in your domain model. Eg.:
public class Country
{
public string Iso { get; set; }
public string Name { get; set; }
public string ContinentIso { get; set; }
public virtual Continent Continent { get; set; }
}
Also, in your controller, return not only the list of countries, but also the list of continents; breeze would make the binding. (not sure that the Include
your have there is necessary).
[HttpGet]
public object Lookups() {
var countries = _breezeRepository.Get<Country>();
var countinents = _breezeRepository.Get<Continent>();
//more lookups in here
return new { countries, continents };
}
Upvotes: 1