Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nik 1611 posts 7237 karma points MVP 7x c-trib
    Jun 07, 2016 @ 10:23
    Nik
    0

    Poco class doesn't populate Id property when fetched back.

    Hi All,,

    I've created a Poco class to store some information. The storeing process is all working fine, the data enters the database, get's a unique id value etc.

    However,

    When I come to recall the information, the Fetch process isn't populating the Id property on my class and I can't for the life of my see why.

    This is my class:

    [TableName("Announcement")]
    [PrimaryKey("Id", autoIncrement = true)]
    [ExplicitColumns]
    public class Announcement : IAnnouncement
    {
        #region Implementation of IAnnouncement
    
        [PrimaryKeyColumn(AutoIncrement = true)]
        public int Id { get; set; }
    
        [Column("NodeId")]
        public int PageId { get; set; }
    
        [Column("Title")]
        public string Title { get; set; }
    
        [Column("Message")]
        public string Message { get; set; }
    
        #endregion
    
    }
    

    This is my code for retrieving the announcements.

    var sql = new Sql().Select("*").From<Announcement>(new SqlCeSyntaxProvider());
    var announcements = DatabaseContext.Database.Fetch<Announcement>(sql);
    

    Any one got any ideas?

  • Nik 1611 posts 7237 karma points MVP 7x c-trib
    Jun 07, 2016 @ 10:37
    Nik
    100

    Found the issue! At long last!

    Changing this line from this:

    [PrimaryKeyColumn(AutoIncrement = true)]
    public int Id { get; set; }
    

    to this:

    [Column("Id")]
    [PrimaryKeyColumn(AutoIncrement = true)]
    public int Id { get; set; }
    

    solved the issue.

Please Sign in or register to post replies

Write your reply to:

Draft