【问题标题】:How to use Linq extension method with CodeFluent Entities template?如何将 Linq 扩展方法与 CodeFluent 实体模板一起使用?
【发布时间】:2014-02-05 04:13:14
【问题描述】:

我目前正在使用 CodeFluent Entities,我想生成一个基于文本的报告,以打印有关我当前模型的一些统计信息。

模板生产者满足了我的所有期望,但我在使用 Linq 扩展方法时遇到了一些问题:

[%@ namespace name="System.Linq" %]

[%= Producer.Project.Entities.Where(entity => entity.IsLightWeight).Count() %]

我收到以下错误消息: 命名空间“System”中不存在类型或命名空间名称“Linq”(您是否缺少程序集引用?)。

有没有办法可以从 CodeFluent 实体模板文件中引用其他程序集?

【问题讨论】:

    标签: c# .net linq templates codefluent


    【解决方案1】:

    您可以在模板文件的开头添加模板指令以添加程序集和命名空间。

    [%@template language="CSharp" providerOptions="CompilerVersion=v3.5" %]
    [%@ Reference name="C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" %]
    [%@ namespace name="System.Linq" %]
    

    【讨论】:

      【解决方案2】:

      在你的 .cs 文件中添加引用

      using System.Linq;
      

      【讨论】:

        猜你喜欢
        • 2017-03-25
        • 2017-05-11
        • 2011-01-07
        • 1970-01-01
        • 1970-01-01
        • 2012-08-03
        • 1970-01-01
        • 2017-12-06
        • 1970-01-01
        相关资源
        最近更新 更多