0

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.

Alan Wayne
  • 5,122
  • 10
  • 52
  • 95
  • The TT files are c# code, so yes, you could alter it. If you're asking how to alter it, then I think you might need to include more detail. For example, the Db type and maybe a sample DDL for a table which holds a column where the `Result` attribute would be applied. – Plebsori Jun 13 '19 at 23:49
  • @Plebsori Please see additions. I am hoping for a simple statement (like what is documented) to add the [ResultColumn] attribute in place of the standard [Column] attribute. I'm afraid rewriting the T4 template is above my skill level. Thanks. – Alan Wayne Jun 14 '19 at 01:50
  • There's currently no support for result columns. If you look at this [file](https://github.com/CollaboratingPlatypus/PetaPoco/blob/development/T4Templates/PetaPoco.Generator.ttinclude) from the repo, you'll see where the poco class is defined (at the bottom), there's no mention of the result column attribute. – Plebsori Jun 14 '19 at 06:09

1 Answers1

2

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; }
}
Plebsori
  • 1,075
  • 9
  • 23
  • one more thing; every fetch or get with simple id parameter will not have that resultColumn included in the select statement, so if you want to display that ResultColumn you must use SP or select * statement to include that column – kite Nov 26 '19 at 01:41