SQLite.Net Update generating error “it has no PK”

2 posts, 0 answers
  1. Prava kafle
    Prava kafle avatar
    213 posts
    Member since:
    Apr 2010

    Posted 17 Mar Link to this post

    Hi,

    I am using SQLite.Net  to store my records for RadListview in Xamarin PCL. I have to update records once users click on list item to modify it's status as already viewed item. Eventhough I have auto increment and primary key attributes on selected columns, autoincrement doesnot sem to work and it always stores '0' for it's value. I have three records in SQLite.Net ORM table each with unique ID, when I try to Update record, it throws 'it has no PK " error. 

    I looked into Xamarin forum too but couldnot find any answers, has anyone encountered this error or knows how to fix it?

    Here is my model:

    public class NotificationSettings

    {

    [PrimaryKey, AutoIncrement]

    public int ID { get; set; }

    public string  NotificationName{ get; set; }

    public string  NotificationValue{ get; set; }

    public bool IsCleanData { get; set; } 

    }

     

    Public class NotificationModifier{

    public  void Update() {

    NotificationSettings  s = database.Table<NotificationSettings>().FirstOrDefault();

    s.IsCleanData = false; //This data is initially  true and is marked false after user reviews it

     database.Update(s) }

    }

     

     

    Thanks,

    Prava

     

     

  2. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1230 posts

    Posted 22 Mar Link to this post

    Hello Prava,

    Your question seem to be unrelated with our components. However, if I were you I would use the naming conventions of EntityFramework CodeFirst approach to create my database. In your case I would use "NotificationSettingsId" instead of "ID" as name of the property.
    In fact in my experience with EF i never had the need to explicitly define an ID field as auto increment. The EF automatically handles the IDs for you. You can take a look at this article it shows how navigation properties should be defined.

    Regards,
    Pavel R. Pavlov
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top