petapoco

Adding [ResultColumn] to Database.tt in PetaPoco


I am an avid user of PetaPoco. Is there any way to tweak the Database.tt (for generation of POCO's) to specify a ResultColumn in a specific table?

TIA

Currently, the Database.tt states:

// Tweak Schema
    tables["tablename"].Ignore = true;                          // To ignore a table
    tables["tablename"].ClassName = "newname";                  // To change the class name of a table
    tables["tablename"]["columnname"].Ignore = true;            // To ignore a column
    tables["tablename"]["columnname"].PropertyName="newname";   // To change the property name of a column
    tables["tablename"]["columnname"].PropertyType="bool";      // To change the property type of a column

I do not know how to change the template, other then these instructions (which work very well). I was hoping for a similar statement that could produce a POCO like:

[TableName("phoenix.view_medical_records")]
    [ExplicitColumns]
    public partial class view_medical_records
    {
        [Column] public string lastname { get; set; }
        [Column] public string firstname { get; set; }
        [Column] public string birthdate { get; set; }
        [Column] public int? chart_number { get; set; }
        [ResultColumn] public DateTime tservice { get; set; }
        [Column] public string status { get; set; }
        [ResultColumn] public DateTime tcompleted { get; set; }
        [Column] public string procedure_description { get; set; }
        [Column] public string description { get; set; }
        [Column] public string provider { get; set; }
    }

Note: the [ResultColumn] attribute being automatically supplied?!

Thanks.


Solution

  • As per my comment on the question, PetaPoco doesn't support result columns via the T4 generator files. However, a workaround would be to ignore the columns

    tables["phoenix.view_medical_records"]["tservice"].Ignore = true;
    tables["phoenix.view_medical_records"]["tcompleted"].Ignore = true;
    

    And, supply partial classes for the generated one which supply the columns.

    public partial Poco1 
    {
        // Generated by PP
    }
    
    public partial Poco1
    {
        // Supplied by the developer (Must be in same namespace)
    
        [ResultColumn] public DateTime tservice { get; set; }
    
        [ResultColumn] public DateTime tcompleted { get; set; }
    }