访问传入查询参数 [英] Accessing Incoming Query Parameters
问题描述
如果没有指定,我想强制执行查询以终止实体传递$ 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屋!