0

after googling for a while, i haven't seen an example on how to create a table with a foreign key with the nuget sqlite-net-pcl for my xamarin.forms app.

Let's say i have GroupTask.cs in which i storethe initial GroupTask:

    [Table("GroupTask")]
    public class GroupTask
    {
        [PrimaryKey, AutoIncrement]
        public int ID { get; set; }
        public string Topic { get; set; }
        public DateTime Date { get; set; }
}

Now i want to create Task.cs which will be used in each GroupTask ( GroupTask contains multiple task). But how do i set it up if possible ?

    [Table("Task")]
    public class Task
    {
        [PrimaryKey, AutoIncrement]
        public int ID { get; set; }
        public string Name { get; set; }
        public string Duration { get; set; }
}

Is it possible with sqlite-net-pcl ? Thanks.

codejourney
  • 319
  • 4
  • 15
  • Oh i didn't remember will it changes anything to my database methods i have right now in my project or i don't have to do anything once it's installed ? – codejourney Jun 26 '20 at 16:16
  • and in my second table under ID, i just have to add [ForeignKey(typeof(GroupTask))] ? – codejourney Jun 26 '20 at 16:29
  • @codejourney Hi ,have a look at this discussion : https://stackoverflow.com/questions/55573511/how-to-create-relationships-with-sqlite-foreign-key . Maybe it will be helpful . – Junior Jiang Jun 29 '20 at 03:26
  • hi @Junior Jang , i think i figured out how to do this but what i'm not sure how to do is the methods to get/delete/add of the foreign key table, maybe you can help on my new post : https://stackoverflow.com/questions/62600651/how-to-add-load-delete-items-from-a-foreign-key-table-in-xamarin-forms-with-sq?noredirect=1#comment110705334_62600651 – codejourney Jun 29 '20 at 13:02

1 Answers1

0

I am sorry, but I cant completely understand what you intend to do. What I CAN help with is showing you the basic form of using a ForeignKey:

[ForeignKey(typeof(Task))]
public string Task1 { get; set;}
[ForeignKey(typeof(Task))]
public string Task2 { get; set;}

ETC.

(As can also be seen here)