2014-03-06 4 views
2

웹 API 2.1 백엔드가있는 프로젝트에 breezejs를 사용하기 시작했습니다. Continental이라는 엔티티에 외래 키/탐색 속성이있는 Country라는 엔티티가 있습니다. 국가를 조회 값으로 사용하고 싶지만 대륙과의 관계도 필요하므로 해당 정보도 가져오고 싶습니다.탐색 속성 BreezeJS 조회

public class Country 
{ 
     public string Iso { get; set; } 
     public string Name { get; set; } 
     public virtual Continent Continent { get; set; } 
} 

나는 또한 continentIso라고하는 FK 필드가 있지만 코드에는 사용하지 않습니다. 같은

는 현재 백엔드 컨트롤러가 보이는 : 나는 개체의 익명의 객체를 반환하고있는 breeze samples으로 당

[HttpGet] 
    public object Lookups() { 
     var countries = _breezeRepository.Get<Country>().Include(it=>it.continent); 
     //more lookups in here   
     return new { countries }; 
    } 

(나는 몇 가지 더 있지만 혼동을 피하기 위해 위에서 그들을 제거). 내가 조회 저장소가 전단 측에

은 (요 파파의 Building Apps with Angular and Breeze - Part 2에 의해 입증) :

function setLookups() { 
    this.lookupCachedData = { 

     countries: this._getAllLocal(entityNames.country, 'name'), 

    }; 
} 

문제가 보낸 JSON은 대륙의 값을 포함하고 있지만, 국가가 포함되지 않은 객체이다 값 또는 탐색 속성을 사용합니다. 대륙을 별도의 조회로 가져 와서 엔티티와 조회를 연결했지만 아무 소용이없는 것처럼 산들 메타 데이터 확장을 통해 연결하려고 시도했습니다.

답변

1

나는 또한 continentIso라고하는 FK 필드가 있지만 코드에는 사용하지 않습니다.

아마도 이것이 here으로 설명한 문제입니다.

나는 다음을 시도 할 것 :

당신이 대륙 FK 명시 적으로 도메인 모델에 정의되어 있는지 확인하십시오. 예 :

public class Country 
{ 
     public string Iso { get; set; } 
     public string Name { get; set; } 
     public string ContinentIso { get; set; } 
     public virtual Continent Continent { get; set; } 
} 

또한 컨트롤러에서 국가 목록뿐만 아니라 대륙 목록도 반환합니다. 산들 바람이 묶일 것입니다. (Include이 필요하다고 확신하지 못합니다.)

[HttpGet] 
public object Lookups() { 
    var countries = _breezeRepository.Get<Country>(); 
    var countinents = _breezeRepository.Get<Continent>(); 
    //more lookups in here   
    return new { countries, continents }; 
} 
+0

필자는 FK가 모델 자체에서는 필요 없지만 엔티티 매핑에서만 필요하다고 생각했지만, 그렇지 않습니다. 키를 추가 했으므로 Include와 함께 작동합니다. – masimplo