Trying to create a fairly simple T4 which I'm trying to load some values that I can use for later:
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="c:\users\<username>\documents\visual studio 2015\Projects\2_DataModelGenerator\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll" #>
<#@ assembly name="c:\users\<username>\documents\visual studio 2015\Projects\2_DataModelGenerator\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll" #>
<#@ assembly name="c:\users\<username>\documents\visual studio 2015\Projects\2_DataModelGenerator\2_Data\bin\Debug\2_Data.dll" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="2_Data" #>
<#@ output extension=".cs" #>
<#
DevEntities dbContext = new DevEntities();
var labelClassNames = (from sd in dbContext.tblDatas
where sd.SID == 155
select new
{
SID = sd.SID.ToString(),
SValue = sd.SValue.ToString()
}).ToList();
#>
When I save the T4 I get this error:
Error Running transformation: System.MissingMethodException: Method not found: 'System.Data.Entity.DbSet`1<2_Data.tblData> 2_Data.DevEntities.get_tblDatas()'
I have tested this code in another solution (using EF 6.1.3) and it works without issue (loads data into var labelClassNames). Seems to be an issue only in T4 template.
Do I need to import another namespace? I'm not sure what I'm missing!
Update:
In my TT code:
dbc context = new dbc();
DevEntities mdc = new DevEntities();
mdc = context.returnContext();
Added a class in my class library:
public class dbc
{
private DevEntities dbContext;
public dbc()
{
dbContext = new DevEntities();
}
public DevEntities returnContext()
{
return dbContext;
}
}
Same error as before:
Running transformation: System.MissingMethodException: Method not found: 'System.Data.Entity.DbSet
However, when I debug the t4 template I get a different message:
No connection string named 'DevEntities' could be found in the application config file.
However, I have copied the App.config file from my class library that include the .edmx file down to my project that contains the .tt file
Any ideas?