2013-04-29 2 views
5

하위 엔티티 컬렉션을 기반으로 엔티티를 필터링하려고합니다. 여기 내 엔티티 (EF POCO의) 위치 : 사용Breeze JS에서 하위 속성 컬렉션을 어떻게 필터링합니까?

public class Customer 
{ 
    public int Id { get; set; } 
    public string Name { get; set; } 
    public ICollection<Order> Orders { get; set; } 
} 

public class Order 
{ 
    public int Id { get; set; } 
    public string Description { get; set; } 
} 

브리즈 JS 내가 어떤 Order.Description 단어 '갑'을 포함하는 모든 고객을 반환합니다. 비슷한 검색어를 상상해 보았습니다.

query = entityQuery.from('Customers') 
        .where("Orders.Description", "contains", "foo"); 

물론 작동하지 않습니다. 어떤 아이디어?

+0

이 바람은 지금이 시나리오를 지원합니다 : http://www.breezejs.com/documentation/query-examples

이이 쿼리는 지금과 같이 구성 될 수 있다는 것을 의미한다 http://www.breezejs.com/documentation/query-examples# 관련 속성에 대한 절은 – robasta

답변

8

바람으로는 불가능합니다. 모든 Order.Description에 'foo'라는 단어가 들어있는 모든 고객을 반환하는 메소드를 구현하는 것이 좋습니다. 백엔드에서

query = entityQuery.from('getCustomerAnyOrderWithFooDescription'); 

: 당신이 웹 API를 사용하는 경우

그것은 뭔가 비슷한 것 또한

[HttpGet] 
public IQueryable<Customer> getCustomerAnyOrderWithFooDescription() 
{ 
    return _contextProvider.Context.Customers.Where(c.Orders.Any(o => o.Description.Contains('foo'))); 
} 

당신이 할 수있는이 같은 일반적인 일을 뭔가 :

query = entityQuery.from('getCustomerAnyOrderWithDescription').withParameters('foo'); 

[HttpGet] 
public IQueryable<Customer> getCustomerAnyOrderWithDescription([FromBody] String someText) 
{ 
    return _contextProvider.Context.Customers 
     .Where(c.Orders.Any(o => o.Description.Contains(someText))); 
} 
+0

두 번째 솔루션이 완벽하게 작동합니다. 감사합니다! – mortware

12

Breeze 1.4.6부터 "모든"및 "모든"쿼리 연산자가 지원됩니다.

참조 :

var query = breeze.EntityQuery.from("Customers") 
    .where("Orders", "any", "Description", "contains", "Foo"); 
+0

이 구문을 시도 할 때마다 다음과 같은 오류가 발생합니다. "TypeError : a is undefined" –

+0

나는 작동하지 않습니다. 아무도 행운을 빕니다. – newman

+0

그래, OData 백엔드에서 제대로 작동하도록했습니다. 현재 승인 된 답변이 현재 유효 기간이 지났기 때문에 승인 된 답변이어야합니다. –

관련 문제