Reputation: 9080
I'm trying to do a fairly simple TF that would generate a list of items, but before I do that I would like to set my DBContext. I'm trying the following:
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Configuration" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Configuration" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="MyProj.Data" #>
<#@ output extension=".cs" #>
namespace ModelGenerator
{
<#
MyProj.Data.ProjectContext db;
#>
}
Compiling transformation: The type or namespace name 'MyProj' could not be found (are you missing a using directive or an assembly reference?)
I'm not sure if I'm doing this right. I'm trying to include the project that has the .EDMX file.
<#@ import namespace="MyProj.Data" #>
In the "MyProj" project has the app.config that has a connection string called "ProjectContext.
I also have a reference in my project that contains the T4 to the MyProj.Data project.
What do I need to do, to get past this error?
Update:
Based off of Yacoub Massad comment. I changed
<#@ import namespace="MyProj.Data" #>
to this:
<#@ assembly name="MyProj.Data" #>
Now I'm getting this error:
Compiling transformation: Metadata file 'MyProj.Data' could not be found
Upvotes: 1
Views: 936
Reputation: 9080
I'm going to leave this question up as I think the assembly name information in the comments are valuable to beginners starting use T4 templates.
The answer to how to actually use your EF DBContext can be found in this question:
T4 - Entity Framework Error: Method not found: 'System.Data.Entity.DbSet`1
This question has an answer with step by step instructions.
Upvotes: 1