Has any document for T4 program?

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
daview
Posts: 8
Joined: Thu 06 Nov 2014 01:45

Has any document for T4 program?

Post by daview » Mon 17 Nov 2014 08:50

I want to code T4 template file, but, I can't find any document about Entity Developer on T4 program.

Sometimes, I just to GUESS to complish the task. And now, it is not successful on Inheritance.

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Has any document for T4 program?

Post by MariiaI » Mon 17 Nov 2014 14:17

Entity Developer templates are written in T4-like Template Language.
Please refer to the corresponding section in the Entity Developer documentation:
- Template System Concepts
- Basic Workflows -> Code Generation
- ORM Support -> Entity Framework -> Customizing Model Properties -> Model
JIC: Entity Developer documentation is available with the installation package (the "Help" component should have been selected when installing).

If this doesn't help, please specify the issues you have encountered with this in more details.

daview
Posts: 8
Joined: Thu 06 Nov 2014 01:45

Re: Has any document for T4 program?

Post by daview » Tue 18 Nov 2014 01:34

Thanks for your reply.

I had checked the Help, but no any reference for T4 program.

Example, I want to generate the EF mapping code on TPH, I want to get the descrimation column name and the condition config to generate the mapping code, but no way.

demo code:

Code: Select all

<#
      if(cls.DerivedClasses.Count > 0 && cls.InheritanceType == InheritanceType.TPH)
      {
        //TPH的继承关系
        string discriminatorColumnName = cls.Name + "_Discriminator";
        string discriminatorColumnValue = cls.Name;
#>
            this.Map<<#= cls.Name #>>(m => 
                {
                    m.Requires("<#= discriminatorColumnName #>")
                        .HasValue("<#= discriminatorColumnValue #>");
                })
<#
        string semicolon = "";
        EntityClass lastDerivedClass = (EntityClass)cls.DerivedClasses.LastOrDefault();
        foreach(EntityClass derivedClass in cls.DerivedClasses)
        {
          if(derivedClass == lastDerivedClass)
          {
            semicolon = ";";
          }
          discriminatorColumnValue = derivedClass.Name;
#>
                .Map<<#= derivedClass.Name #>>(m =>
                {
                    m.Requires("<#= discriminatorColumnName #>")
                        .HasValue("<#= discriminatorColumnValue #>");
<#
          foreach(EntityProperty property in derivedClass.Properties)
          {
            GenerateTPHProperty(derivedClass.ClassMapping, property, null);
          }
#>
                })<#= semicolon #>
<#
        }
      }
#>

MariiaI
Devart Team
Posts: 1472
Joined: Mon 13 Feb 2012 08:17

Re: Has any document for T4 program?

Post by MariiaI » Wed 19 Nov 2014 11:41

daview wrote:Example, I want to generate the EF mapping code on TPH, I want to get the descrimation column name and the condition config to generate the mapping code, but no way.
demo code:...
Which exactly errors you are getting with this code? For example, we have tried it and the syntax seems to be correct.
Also, if the question is about the common principles of working with T4 templates and its syntax, then we recommend you to refer to specific forums regarding it.
If the question is about how to modify Entity Developer predefined templates, then please specify the question more detailed, e.g.:
- what code should be generated and for which scenarios;
- what errors and warnings occur while code generation, etc.;

Post Reply