简体   繁体   English

如何使用Lambda / Linq过滤WCF服务结果

[英]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.

相关问题 如何将Lambda表达式传递给WCF服务? - How can I pass a lambda expression to a WCF service? 如何将Web服务的结果合并为动态类型,我可以使用Linq的Zip或Lambda函数来查找要合并的行 - How to merge the results of a web service to a dynamic type, can I use Linq's Zip or a Lambda function to find the row to merge 如何根据另一个 LINQ 查询过滤结果? - How can I filter results of one LINQ query based on another? 如何过滤列表 <object> 使用Linq / Lambda - How to filter List<object> using Linq/Lambda 如何在 C# 中使用 LINQ 过滤嵌套字典? - How can I filter a nested dictionary using LINQ in C#? 如何使用 generics 和 Linq 扩展方法过滤列表? - How can I filter a list using generics and Linq extension methods? 使用LINQ,如何在部分字符串属性上过滤集合? - Using LINQ, how can I filter a collection on partial string property? 如何使用LINQ / Lambda将结果选择到在对象内声明的对象中? - How to select results into an object declared within an object using LINQ/Lambda? 如何使WCF数据服务查询拦截器返回JSON结果? - How can I make a WCF Data Service Query Interceptor return results in JSON? 我如何过滤Linq结果以仅返回选择的XML列 - how can i filter the Linq results to only return selected XML column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM