PetaPoco/NPoco - calculated properties in poco

1.8k views Asked by At

I am using PetaPoco/NPoco in my project. The database schema I am working with was not thought our very well and therefore I can't directly bind the POCO to my wpf mvvm view (which is what I used to be able to do when I was also creating the database schema). I am considering two possible solutions to this problem:

  1. Add unmapped properties to the POCO
  2. Create a wrapper for the pocos with a reference to the poco

Does a proven pattern exist for this problem?

1

There are 1 answers

1
Eduardo Molteni On BEST ANSWER

You can manipulate the PetaPoco maps as you wish using ExplicitColumns to map to a different named column. You can also use ResultColumn for properties that you wish to grab from the DB for not update/insert. Finally, you can also use unmapped properties for extra work not related to the DB.

namespace Site.Models {
    [TableName("Hotel")]
    [PrimaryKey("HotelID")]
    [ExplicitColumns]
    public class Hotel {
        [PetaPoco.Column("HotelID")]
        public int HotelID { get; set; }

        [PetaPoco.Column("HotelClaseID")]
        public int? HotelClaseID { get; set; }

        [ResultColumn]
        public string HotelClase { get; set; }

        [Required]
        [PetaPoco.Column("Nombre")]            
        public String Nombre { get; set; }

        ....