Search code examples
c#entity-frameworkt4edmx

Check entity type at the tt file


I need to overwrite the Model.tt file, to add some special code to be generated to the constructor of a specific entity type.

I have two questions:

  1. How to check the entity type?
  2. How to call a method inside the generated constructor?

Solution

  • I got it! Just putting these lines of code inside the constructor section at the tt file public <#=code.Escape(entity)#>()

    <#        
        if(entity.Name == "Order")
        {
    #>
         this.Initialize();
    <#
        }
    #>