我正在尝试根据子实体的集合过滤实体.这是我的实体(EF POCO):
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; }
}
Run Code Online (Sandbox Code Playgroud)
使用Breeze js我想要返回任何Order.Description包含单词'foo'的所有客户.我想象查询看起来像这样:
query = entityQuery.from('Customers')
.where("Orders.Description", "contains", "foo");
Run Code Online (Sandbox Code Playgroud)
但当然这不会奏效.有任何想法吗?
Jay*_*and 13
从Breeze 1.4.6开始,Breeze现在支持"any"和"all"查询运算符.
请参阅:http://www.breezejs.com/documentation/query-examples
这意味着此查询现在可以组成为:
var query = breeze.EntityQuery.from("Customers")
.where("Orders", "any", "Description", "contains", "Foo");
Run Code Online (Sandbox Code Playgroud)
微风是不可能的.我建议您在您的支持中实现一个方法,该方法返回任何Order.Description包含单词'foo'的所有客户.
如果您使用的是Web API,它将类似于:
query = entityQuery.from('getCustomerAnyOrderWithFooDescription');
Run Code Online (Sandbox Code Playgroud)
在你的后端:
[HttpGet]
public IQueryable<Customer> getCustomerAnyOrderWithFooDescription()
{
return _contextProvider.Context.Customers.Where(c.Orders.Any(o => o.Description.Contains('foo')));
}
Run Code Online (Sandbox Code Playgroud)
你也可以这样做更通用的做这样的事情:
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)));
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2641 次 |
| 最近记录: |