我想要能够使用lambda表达式来指定一个值,以便通过wcf服务返回 [英] I want to be able to use a lambda expression to specify a range of values to return over a wcf service

查看:226
本文介绍了我想要能够使用lambda表达式来指定一个值,以便通过wcf服务返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如果这是可能的...但它会很酷。问题是是否可能,但是如果可能的话,可能会有一个例子。



我不知道用什么方法签名来传递lambda表达式。 / p>

例如方法 IList<组> GetGroups()



您将如何修改以便将lambda表达式传递给它?



下一个问题是如何编写lambda表达式以返回所有Group对象,例如




  • where .deleted == false

  • 其中.DateAdded> aDate



是的,我想把月亮放在棍子上;)
提前感谢。



(编辑我认为这实际上是因为实际获取数据的数据访问层,但假设您正在查询一些

解决方案

您可以声明 GetGroups 方法,参数类型为 Expression< Func< Group,bool>> ,表示组必须匹配的谓词订单返回:

  IList<组> GetGroups(表达式< Func< Group,bool>> predicateExpression); 

麻烦的是,表达式不能序列化,所以你不能发送到WCF服务...但是,您可能会找到一种方法,使用表达式树序列化项目


I have no idea if this is possible ... but it would be cool. the question is whether it is possible but then a bit of an example if possible.

I am not sure what method signature you would use to pass the lambda expression into.

Eg the method IList<Group> GetGroups()

How would you modify that to be able to pass a lambda expression into it?

The next question is how would you code a lambda expression to return all Group objects where for example

  • where .deleted == false or
  • where .DateAdded > aDate

Yeah, I want the moon on a stick ;) Thanks in advance.

(edit I am thinking this is a bit ill-conceived actually because of the data access layer that would actually fetch the data ... but assume that you are querying some object collection over the service and don't have to worry about the dal).

解决方案

You could declare the GetGroups method with a parameter of type Expression<Func<Group, bool>>, which represents a predicate that the group must match in order to be returned :

IList<Group> GetGroups(Expression<Func<Group, bool>> predicateExpression);

The trouble is, expressions can't be serialized, so you couldn't send it to the WCF service... However, you might find a way to do it with the Expression Tree Serialization project.

这篇关于我想要能够使用lambda表达式来指定一个值,以便通过wcf服务返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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