I can't figure this one out. Why doesn't T4 locate the IEnumerable
type? I'm using Visual Studio 2010. And I just hope someone knows why?
<#@ 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())
{
}
}
}
}
#>
Error 2 Compiling transformation: The type or namespace name 'IEnumerable' could not be found (are you missing a using directive or an assembly reference?) c:\Projects\T4BuildApp\T4BuildApp\TextTemplate1.tt 26 9
To debug a design-time text template, save the text template file, and then choose Debug T4 Template on the shortcut menu of the file in Solution Explorer. To debug a run-time text template, simply debug the application to which it belongs.
t4 template is used to scaffold a DbContext class for the database, and the EntityType. t4 template is used to scaffold entity type classes for each table and view in the database.
T4 stands for Text template transformation toolkit is template based code generation engine. So you can write C# code in T4 templates ( . tt is the extension) files and those c# codes execute to generate the file as per the written C# logic.It is used in Entityfreamework, MVC to create strongly type views.
I would also recommend to referece #assembly name="System.Core" and #import "System.Linq" so you get more power when doing something with IEnumerable
Probably because IEnumerable is in System.Collections
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With