随时随地获取所有信息使用 ExpressionVisitor 进行调用
我有一个查询,如下所示:
var query = from sessions in dataSet
where (names.Contains(sessions.Username))
where (sessions.Login.TimeOfAction == dt)
select new { sessions.Username,
sessions.Login,
sessions.Logout, sessions.Duration };
我想实现一个 ExpressionVisitor 来提取两个 where 子句作为 Lambda 的子句,但到目前为止只能使用一个名为“InnermostWhereFinder”的类来获取第一个子句,该类来自自定义的 MSDN 教程TerraServer Web 服务的查询提供程序。
它是:
internal class InnermostWhereFinder : ExpressionVisitor
{
private MethodCallExpression innermostWhereExpression;
public MethodCallExpression GetInnermostWhere(Expression expression)
{
Visit(expression);
return innermostWhereExpression;
}
protected override Expression VisitMethodCall(MethodCallExpression expression)
{
if (expression.Method.Name == "Where")
innermostWhereExpression = expression;
Visit(expression.Arguments[0]);
return expression;
}
}
我尝试大力调整这个类以返回两个 where 子句,但没有成功。找不到这方面的任何重要文档,有人可以帮忙吗?我认为,这最终需要产生多个我可以使用的 LambdaExpression 对象。
I have a query, like such:
var query = from sessions in dataSet
where (names.Contains(sessions.Username))
where (sessions.Login.TimeOfAction == dt)
select new { sessions.Username,
sessions.Login,
sessions.Logout, sessions.Duration };
I want to implement an ExpressionVisitor to extract BOTH the where clauses as Lambda's, but so far have only been able to get the first using a class called 'InnermostWhereFinder' that comes from the MSDN tutorial on a custom query provider for the TerraServer web-service.
It is:
internal class InnermostWhereFinder : ExpressionVisitor
{
private MethodCallExpression innermostWhereExpression;
public MethodCallExpression GetInnermostWhere(Expression expression)
{
Visit(expression);
return innermostWhereExpression;
}
protected override Expression VisitMethodCall(MethodCallExpression expression)
{
if (expression.Method.Name == "Where")
innermostWhereExpression = expression;
Visit(expression.Arguments[0]);
return expression;
}
}
Ive tried tweaking this class heavily to return both where clauses with no success. Couldn't find any great documentation on this, can anyone help? This will ultimately need to result in multiple LambdaExpression objects I can work with, I think.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用此处找到的类 http://msdn.microsoft.com/en -us/library/bb882521%28v=vs.90%29.aspx 作为您的基础。然后你可以像这样创建你的访客
Use the class found here http://msdn.microsoft.com/en-us/library/bb882521%28v=vs.90%29.aspx as your base. You can then create your Visitor like this