CodeDom编译GroupBy的问题 [英] CodeDom compiling problem with GroupBy

查看:104
本文介绍了CodeDom编译GroupBy的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CodeDom编译以下代码段:

I'm trying to compile the following snippet with CodeDom:

var res = from x in q.Rows
group x by x.Product into g
select new 
{
    Product = g.Key,
    TotalPrice = g.Sum(p => p.Price),
    TotalQTY = g.Sum(p => p.QTY)
};

return q.ToList<object>();

使用以下参考资料:

With the following references :

compilerparams.ReferencedAssemblies.Add(typeof(object).Assembly.Location); //mscorlib.dll
compilerparams.ReferencedAssemblies.Add(typeof(System.Uri).Assembly.Location); //system.dll
                compilerparams.ReferencedAssemblies.Add(typeof(System.Linq.Enumerable).Assembly.Location);//system.core.dll



但是编译器抱怨它无法找到 GroupBy ToList 扩展方法。

推荐答案

添加适当的using子句;与该语言的其他语法功能不同,当您可以使用完整类型名称或别名时,扩展方法需要使用using子句和声明扩展方法的命名空间。



-SA
Add appropriate "using" clause; unlike other syntactic features of the language, when you can use full type names or alias using, extension methods require "using" clause with the namespace where the extension method is declared.

—SA


这篇关于CodeDom编译GroupBy的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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