如何将 lambda 表达式传递给 WCF 服务? [英] How can I pass a lambda expression to a WCF service?

查看:33
本文介绍了如何将 lambda 表达式传递给 WCF 服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的项目使用 IDesign 架构,所以我所有的层都是服务.我想让我的资源访问层的 CRUD 中的 Read 方法采用 lambda 表达式形式的谓词以及要拉取的相关对象列表.这样资源访问层就会非常通用.

My current project is using the IDesign architecture, so all of my layers are services. I wanted to have my Read method in the CRUD of my resource access layer take a predicate in the form of a lambda expression as well as a list of related objects to pull. This way the resource access layer will be very generic.

[OperationContract]
Result<MyObject> ReadObjects(Func<MyObject, bool> predicate, string[] includes);

现在我发现了一些应该很明显的事情,那就是我无法序列化 lambda 表达式.我研究过将字符串解析为 lambda 表达式,但这也不行.

Now I have come to discover something that should have been obvious, and that is that I cannot serialize lambda expressions. I looked into parsing a string into a lambda expression, but that is a no go as well.

是否有任何方法可用于将 lambda 表达式传递给服务?有没有更好的方法来做我想做的事情?

Is there any method that I can use to pass a lambda expression to a service? Is there a better way to do what I am trying to do?

推荐答案

也许动态查询适用于您的情况?

Perhaps a dynamic query would work in your situation?

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

您将一个 where 子句字符串传递给服务,该服务将验证并将其转换为表达式

You would pass a where clause string to the service which would validate and convert it to an expression

这篇关于如何将 lambda 表达式传递给 WCF 服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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