BreezeJS:在控制器中应用客户端查询 [英] BreezeJS: Applying Client Query in Controller

查看:40
本文介绍了BreezeJS:在控制器中应用客户端查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

反正有没有在控制器中应用用户查询以便对最终结果集执行某些操作?

Is there anyway to apply the user query in the controller in order to perform some actions to the final result set?

以下面的示例为例:

[HttpGet]
public IQueryable<Container> Containers(bool populate)
{
    var containers = _contextProvider.Context.Containers;
    if (populate)
    {
         foreach (var container in containers)
         {
             container.Populate(_contextProvider.Context);
         }
    }
    return containers;
}

这里的问题是我正在这样做人口()操作此表中的所有记录,而不仅仅是用户请求的记录(因为尚未应用他们的查询)。我该如何实现?

The problem here is that I am doing this Populate() action to all records in this table instead of just the ones that the user requested because their query has not been applied yet. How can I achieve this?

推荐答案

您需要将ODataQueryOptions传递到您的方法中,以便可以手动应用它们而不是

You need to get the ODataQueryOptions passed into your method, so you can apply them manually instead of letting WebApi apply them on the way out.

[HttpGet]
public IQueryable<Container> Containers(ODataQueryOptions options, bool populate)
{
    IQueryable<Container> containers = _contextProvider.Context.Containers;
    containers = options.ApplyTo(Containers).Cast<Container>();
    if (populate)
    {
        foreach (var container in containers)
        {
            container.Populate(_contextProvider.Context);
        }
    }
    return containers;
}

这篇关于BreezeJS:在控制器中应用客户端查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆