我無法弄清楚這一點。爲什麼T4沒有找到IEnumerable
類型?我正在使用Visual Studio 2010.我只希望有人知道爲什麼?T4故障編譯轉換
<#@ template debug="true" hostspecific="false" language="C#" #>
<#@ assembly name="System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ output extension=".cs" #>
public static class Tables
{
<#
var q = @"
SELECT
tbl.name 'table',
col.name 'column'
FROM
sys.tables tbl
INNER JOIN
sys.columns col ON col.object_id = tbl.object_id
";
// var source = Execute(q);
#>
}
<#+
static IEnumerable Execute(string cmdText)
{
using (var conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=t4build;Integrated Security=True;"))
{
conn.Open();
var cmd = new SqlCommand(cmdText, conn);
using (var reader = cmd.ExecuteReader())
{
while (reader.Read())
{
}
}
}
}
#>
錯誤2編譯轉型:類型或命名空間名稱 'IEnumerable的' 找不到(是否缺少using指令或程序集引用嗎?)C:\項目\ T4BuildApp \ T4BuildApp \ TextTemplate1.tt 26 9
....約翰做的事情時,你得到更多的權力來referece #assembly NAME =「System.Core程序」和#進口「System.Linq的」 - 你不要將'System.Collections'命名空間導入你的模板 – 2010-05-09 19:29:49
哦,我怎麼可能沒有看到這個。謝謝!我肯定已經失明瞭一個小時左右... – 2010-05-10 21:33:55