Search code examples
c#sqlsql-serverormpetapoco

Difference Between Column and ResultColumn Using Petapoco?


I have Class like

 public class Myclass
    {
        [Column]
        public string no{ get; set; }
        [Column]
        public string Name{ get; set; }
        [Column]
        public string Address{ get; set; }
        [Column]
        public DateTime DOB{ get; set; }
    }

and my select query is

List<Myclass> list=DAL.db.Fetch("select b.ref_no no,a.name,a.Address,a.DOB from tbla a join tblb b on b.id=a.ref_id");

Sometimes I get the wrong result that is I got the same record.I guess my class decoration changed to like this,

 public class Myclass
    {
        [ResultColumn]
        public string no{ get; set; }
        [ResultColumn]
        public string Name{ get; set; }
        [ResultColumn]
        public string Address{ get; set; }
        [ResultColumn]
        public DateTime DOB{ get; set; }
    }

Solution

  • Column

    Is an attribute which can decorate a Poco property to mark the property as a column. It may also optionally supply the DB column name.

    ResultColumn

    Is an attribute which can decorate a Poco property as a result only column. A result only column is a column that is only populated in queries and is not used for updates or inserts operations.

    See here https://github.com/CollaboratingPlatypus/PetaPoco/wiki/Mapping-Pocos