访问传入查询参数 [英] Accessing Incoming Query Parameters

查看:81
本文介绍了访问传入查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果没有指定,我想强制执行查询以终止实体传递$ top = n语句或将$ top设置为n。

在beta版本中,这可以通过以下方式实现:

[ QueryInterceptor (< span style ="color:#a31515">" trace" )]


public IQueryable < 微量> InterceptTrace( IQueryable < trace > incomingQuery)


{


return incomingQuery.Take(100);
}

但现在我们无法访问incming查询:


[ QueryInterceptor " trace" )]


public 表达式< Func < trace bool >> FilterTrace()


{


return (c => / *搜索表达式* / );


}

另外,MSDN示例似乎避免了CurrentDataSource上有一个QueryRules属性的事实。但它似乎不存在:


[QueryInterceptor(" Customers")]


public Expression< Func< Customer,bool>> FilterCustomers()


{


返回c => c.Name == / *当前主要名称。 * /&&


this.CurrentDataSource.QueryRules.Contains(


rule => rule.Name == c.Name&&


rule.CustomerAllowedToQuery == true


);


}



所以:
1)我们怎样才能在interceptor中获取传入的查询?
2)我们如何限制返回的行数?






Scott Prugh

解决方案

< blockquote>嗨Scott
,您可以通过在InitializeService方法中设置IDataServiceConfiguration上的MaxResultsPerCollection属性来限制实体集返回的结果数量

http://msdn.microsoft.com/en-us/library/system.data.services.idataserviceconfiguration.maxresultspercollection.aspx

I would like to enforce  queries for cerating entities to pass the $top=n statement or set $top to n if not specified.

In beta versions this was possible with:

        [QueryInterceptor("trace")]

        public IQueryable<trace> InterceptTrace(IQueryable<trace> incomingQuery)

        {

            return incomingQuery.Take(100); 
        }

but now we don't have access to the incming query:

        [QueryInterceptor("trace")]

        public Expression<Func<trace, bool>> FilterTrace()

        {

            return (c => /* search expression here */ );

        }

Also, the MSDN sample seems to elude to the fact that there is a QueryRules property on the CurrentDataSource.  But it doesn't seem to exist:

[QueryInterceptor ("Customers")]

public Expression<Func<Customer, bool>> FilterCustomers()

{

  return c => c.Name == /* Current principal name. */ &&

              this.CurrentDataSource.QueryRules.Contains(

                rule => rule.Name == c.Name &&

                        rule.CustomerAllowedToQuery == true

              );

}


So:
1) How can we get at the incoming query in an intereceptor?
2) How do we limit the number of rows returned?






Scott Prugh

解决方案

Hi Scott
, You can limit the number of results returned for an entity set by setting the MaxResultsPerCollection property on IDataServiceConfiguration in the InitializeService method 

http://msdn.microsoft.com/en-us/library/system.data.services.idataserviceconfiguration.maxresultspercollection.aspx


这篇关于访问传入查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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