Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving some situations with T4 Templates
    primarykey
    data
    text
    <p>I am trying to create a T4 Template for a custom controller (with services). However, I am having some issues setting things up. I currently use tangible free T4 tool editor and TextTemplatingFileGenerator as a Custom Tool. I am running into a couple issues when experimenting:</p> <p>1: I try using MvcTextTemplateHost mvcHost = (MvcTextTemplateHost)(Host); and it says "The type or namespace name MvcTextTemplateHost could not be found (are you missing a using directive or an assembly reference?). It says to clear the Custom tool, but I was wondering how I can view the generated T4 file if I do clear the tool?</p> <p>2: Another approach was Steve Sanderson's CustomTemplate but I am having issues there with the DynamicTransform not being found and was wondering where I can get the file needed to use it. If i need to clear the tool for this, then how do I view a generated sample file? Thank you very much.</p> <p>Max Gilman</p> <p>Some sample code:</p> <pre><code>&lt;#@ Template Language="C#" HostSpecific="True" Inherits="DynamicTransform" #&gt; &lt;#@ Output Extension="cs" #&gt; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; namespace someNamespace { &lt;# var modelType = (CodeType)Model.ModelType; var modelName = modelType.Name; var modelNamePlural = Model.ModelTypePluralized; var modelVariable = modelName.ToLower(); var relatedEntities = ((IEnumerable)Model.RelatedEntities).OfType&lt;RelatedEntityInfo&gt;(); var primaryKeyProperty = modelType.VisibleMembers().OfType&lt;CodeProperty&gt;().Single(x =&gt; x.Name == Model.PrimaryKey); var routingName = Regex.Replace(Model.ControllerName, "Controller$", "", RegexOptions.IgnoreCase); var isObjectContext = ((CodeType)Model.DbContextType).IsAssignableTo&lt;System.Data.Objects.ObjectContext&gt;(); #&gt; public class foo { //This is a basic comment. } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload