2014-12-24 3 views
0
Expression<Func<SystemUser, object>>[] includeProperties = { 
    x => x.Company.CompanyAddresses.Where(z=>z.AddressTypeId==5) 
            .Select(y => y.Address.Country.CountryRegions) 
}; 
var user = _SystemUserRepository.GetById(userID, includeProperties); 

을 포함하면 예외가 발생합니다. "포함 경로 표현식은 유형에 정의 된 탐색 속성을 참조해야합니다. 참조 탐색 속성 및 선택 연산자에 점선으로 된 경로 사용 컬렉션 탐색 속성 용. "위의 쿼리를 실행하는 동안 경로 표현 트리 오류

쿼리에서 where 절을 제거하면 정상적으로 실행됩니다.

이유를 설명 할 수 있습니까?

답변

1

먼저 속성을 포함해야합니다. 이 같은

시도 뭔가 :

x => x.Company.Include(y=>y.CompanyAddresses) 
       .Where(z=>z.CompanyAddresses.AddressTypeId==5) 
       .Select(y => y.Address.Country.CountryRegions) 

당신은 또한 this post을 참조하여이 SO Post (conditional include in linq to entities)

를 확인하실 수 있습니다