Search code examples
umbraco7petapoco

PetaPoco returns empty object


Inside my applocation, the petapoco poco returns an empty object (all values are null). Using the UI-O-Matic Nuget package inside my Umbraco 7.5.12.

The query i'm currently running:

var dbContext = ApplicationContext.Current.DatabaseContext;

    var objects = dbContext.Database.Fetch<ObjectDB>("select Id, Name, CreatedOn, PlaceId, InActive, CityMapping, CountryIsoMapping, Globalsearch from ObjectsDB");
    return objects.Where(n => n.PlaceId == PlaceId).FirstOrDefault();

TableDB is my PetaPoco model with the fields like:

[UIOMatic("ObjectsDB", "Object", "Object", FolderIcon = "icon-globe-inverted-europe-africa", ItemIcon = "icon-pin-location", RenderType = UIOMaticRenderType.List)]
        [TableName("ObjectsDB")]
        [PrimaryKey("Id", autoIncrement = false)]
        [ExplicitColumns]
        public class ObjectDB
        {
            [PrimaryKeyColumn(AutoIncrement = true)]
            public int Id { get; set; }

            [UIOMaticListViewFilter]
            [UIOMaticListViewField(Name = "Name")]
            [UIOMaticField(Name = "Name", Description = "Name")]
            public string Name { get; set; }
}

When debuging:

`Debug result: con.Single<ObjectsDB>("select Name, Id from ObjectsDB where Id = 4") 

This retruns the object:

    {Umbraco.Extensions.Models.Custom.ObjectsModel.ObjectsDB} _createdOn: {1/1/0001 12:00:00 AM} 
CityMapping: null 
CountryIsoMapping: null 
CreatedOn: {5/19/2017 4:22:16 PM} 
Globalsearch: false 
Id: 0 
InActive: false 
InCache: false 
Name: null 
Object: null 
PlaceId: null `

Inserting data is working with the same dbContext, that's working. What am I missing here?


Solution

  • Removing the attribute [ExplicitColumns] above my class fixed the problem. No everything works as expected. Also the other decorations are working. So @Nurhak Kaya was partially right. After removing that attribute deleting the table and rebuild / generating the table.