解析字符串转换成LINQ查询 [英] Parse string into a LINQ query

查看:614
本文介绍了解析字符串转换成LINQ查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用什么方法将被视为最佳实践解析LINQ字符串转换成一个查询?

What method would be considered best practice for parsing a LINQ string into a query?

或者换句话说,什么样的方法是最有意义的转换:

Or in other words, what approach makes the most sense to convert:

 string query = @"from element in source
                  where element.Property = ""param""
                  select element";

 IEnumerable<Element> = from element in source 
                        where element.Property = "param"
                        select element;

假设的IEnumerable&LT;组件&gt; 的IQueryable&LT;组件&gt; 在局部范围内。

assuming that source refers to an IEnumerable<Element> or IQueryable<Element> in the local scope.

推荐答案

这需要一定的文本分析和大量使用的 System.Linq.Ex pressions 。我做了一些玩弄这种 rel="nofollow">和的此处。在code在第二篇文章中有所从第一,但仍然粗糙的斑点更新。我继续乱轮这对场合和有我一直张贴如果您有任何兴趣有点清洁的版本。我知道了pretty的密切支持ANSI SQL 89良好的子集。

It requires some text parsing and heavy use of System.Linq.Expressions. I've done some toying with this here and here. The code in the second article is somewhat updated from the first but still rough in spots. I've continued to mess round with this on occasion and have a somewhat cleaner version that I've been meaning to post if you have any interest. I've got it pretty close to supporting a good subset of ANSI SQL 89.

这篇关于解析字符串转换成LINQ查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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