Ⲁⲅⲅⲉⲗⲟⲥ
Ⲁⲅⲅⲉⲗⲟⲥ

Reputation: 668

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?

Upvotes: 0

Views: 202

Answers (2)

Ⲁⲅⲅⲉⲗⲟⲥ
Ⲁⲅⲅⲉⲗⲟⲥ

Reputation: 668

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();
<#
    }
#>

Upvotes: 0

Anupam Sharma
Anupam Sharma

Reputation: 368

You can try having another partial class as your generated entity class. Write your custom logic in this partial class. e.g.

Your entity class is Customer.cs Create another Customer.cs partial class in same namespace but separate folder(maybe) and add your logic there. You should be able to use it.

Upvotes: 1

Related Questions