This is a migrated thread and some comments may be shown as answers.

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

1 Answer 978 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Prava kafle
Top achievements
Rank 1
Prava kafle asked on 17 Mar 2017, 01:19 PM

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

 

 

1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 22 Mar 2017, 08:20 AM
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
Tags
General Discussions
Asked by
Prava kafle
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or