linQ to lambda翻译在linQpad4中不起作用

时间:2013-05-14 15:01:56

标签: c# linqpad

我第一次使用LinQPad4。我在程序中运行了一个LinQ查询示例,当我按下Lambda底部时,程序没有显示转换为Lambda的查询,有人可以帮我吗?

var words = from word in "The quick brown fox jumps over the lazy dog".Split() 
            orderby word.ToUpper() 
            select word; 
var duplicates = from word in words 
                 group word.ToUpper() by word.ToUpper() 
                 into g 
                 where g.Count() > 1 
                 select new { g.Key, Count = g.Count() };
words.Dump(); 
duplicates.Dump();

1 个答案:

答案 0 :(得分:4)

如果是本地查询,则需要在查询中插入.AsQueryable(),以便生成表达式树。内置示例关于AsQueryable的注释

对此进行了解释
var names = new[] { "Tom", "Dick", "Harry", "Mary", "Jay" }.AsQueryable();

// AsQueryable() doesn't change the result of the query. The effect it has it to populate 
// the λ tab below—so you can see how the query translates into lambda (fluent) syntax.
// To illustrate, press F5 to run the following:
(
    from n in names
    where n.Length > 3
    orderby n descending
    select n.ToUpper()
)
.Dump ("Click the λ button - notice the translation to fluent syntax");