我不知道这是否可能......但这会很酷。问题是这是否可能,但如果可能的话,举一个例子。
我不确定您将使用什么方法签名来将 lambda 表达式传递到其中。
例如,方法IList GetGroups()
您将如何修改它以便能够将 lambda 表达式传递给它?
下一个问题是如何编写 lambda 表达式以返回所有 Group 对象,例如
where .deleted == false
或
where .DateAdded > aDate
是的,我想要棒上的月亮;)
提前致谢。
(编辑我认为这实际上有点考虑不周,因为数据访问层实际上会获取数据......但假设您正在通过服务查询某些对象集合,并且不必担心 dal )。
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).
发布评论
评论(4)
您可以
Matt Warren 有十七篇博客文章介绍如何执行此类操作。
You could
Matt Warren has seventeen blog articles about how to do this sort of thing.
我认为 RIA 服务可以满足您的要求,但我不知道其背后的魔力。
I think that RIA services do what you want, but I do not know the magic behind it.
您可以传递一个“谓词”:
Func
,它为给定的 Group 返回 true 或 false。由于您可以在需要Func
的位置传递 lambda,因此可能类似于:var fooGroups = GetGroups(g => g.Name.StartsWith("Foo"));< /代码>
You could pass a "predicate": A
Func<Group, bool>
, which returns true or false for a given Group. Since you can pass a lambda where aFunc
is expected, this could be something like:var fooGroups = GetGroups(g => g.Name.StartsWith("Foo"));
您可以使用
Expression>
类型的参数声明GetGroups
方法,该参数表示该组必须匹配才能返回的谓词:问题是,表达式无法序列化,因此您无法将其发送到 WCF 服务...但是,您可能会找到一种方法来使用 表达式树序列化 项目。
You could declare the
GetGroups
method with a parameter of typeExpression<Func<Group, bool>>
, which represents a predicate that the group must match in order to be returned :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.