如何传递一个Lambda EX pression到WCF服务?EX、Lambda、WCF、pression

2023-09-02 21:53:36 作者:爲了妳↘我壹切可以遷就

我现在的项目是使用■设计架构,所以我所有的层服务。我想在我的资源接入层的CRUD我读法采取了predicate在一个lambda EX pression的形式以及相关对象的拉列表。这样,资源接入层将是非常通用的。

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);

现在我是来发现的东西,应该是显而易见的,那就是我不能序列化拉姆达EX pressions。我看着解析字符串为lambda EX pression,但是这是一个没有去为好。

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 EX pression到服务的任何方法?有没有更好的办法做我想要做什么?

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子句字符串的服务,将验证并将其转换为一个前pression

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