[英]How can I filter WCF service results using lambda / linq
I am planning a WCF service to return lists, data, all the usual things. 我正在计划一个WCF服务以返回列表,数据和所有常见的东西。
Now I saw on here ages ago that as of .NET 4.5 you could pass lambda expressions or filters to WCF (I also saw something in a pluralsight video somewhere) that allowed you to write something along the lines of 现在,我很久以前就在这里看到,从.NET 4.5开始,您可以将Lambda表达式或过滤器传递给WCF(我在某处的复数视频中也看到了某些内容),使您可以按照
IQuerable<string> GetInfo();
// or
List<string> GetInfo(Expression predicate);
Instead of 代替
GetInfo(int page, int resultsPerPage, bool sortAsc, string sortColumn);
However, as I'm reading around I see lots of conflicting (and old) information saying that this isnt possible. 但是,当我在阅读时,看到很多相互矛盾的(旧的)信息说这是不可能的。 Is it then at all possible to filter WCF results before they are returned via some linq or lambda expression?
那么在通过linq或lambda表达式返回 WCF结果之前,是否有可能对其进行过滤?
Update 更新资料
I have implemented a Service (WCF not WCF Data Services) like so, and I get the expected result. 我已经实现了这样的服务(WCF不是WCF数据服务),并且得到了预期的结果。 Is the client actually passing the query to the web service or is it being rendered client side?
客户端实际上是将查询传递给Web服务,还是正在呈现给客户端?
public class Service1 : IService1
{
public IQueryable<string> DoWork()
{
List<string> strings = new List<string>();
for (char c = 'a'; c < 'z'; c++)
{
strings.Add(c.ToString());
}
return strings.AsQueryable();
}
}
Client: 客户:
Service1 s = new Service1();
var results = s.DoWork();
var results1 = results.Where(str => str == "a"); // works
看起来您需要WCF数据服务 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.