Sqlite One to Many Relationship

痴心易碎 提交于 2019-12-07 05:46:27

问题


I'm currently making an app that needs to store and get data to and from a sqlite database. The two Nuget packages I'm currently using are Sqlite PCL and SQLite-Net Extensions.

[Table("patient")]
public class Patient
{
[PrimaryKey]
public string ID { get; set;}

    public string FirstName { get; set; }
    public string LastName { get; set; }

    [OneToMany]
    public List<PatientVitals> PatientVitals { get; set; }
}

[Table("patientVitals")]
public class PatientVitals
{
    [PrimaryKey]
    public string VitalID {get;set;}

    public string Weight { get; set;}
    public string Height { get; set;}

    [ForeignKey(typeof(Patient))]
    public string SmartCardID {get;set;}
}

The whole thing is compiled fine, but when I try to run the simulator I'm getting this message:

System.NotSupportedException has been thrown Don't know about System.Collections.Generic.List1

I checked the SQLite-Net Extensions documentation and it does support List.

Does anyone know how to fix this?


回答1:


Please add the primary key of Patient as Foreign key in table PatientVitals.




回答2:


Anyway, after some research, it turned out that I had to remove all of the SQLite related nudgets and re-install them into the project. In my case, since I need the SQLite-Net Extensions, I only need to put it in my project and any dependencies nudgets will also be installed along with SQL-Net Extensions.



来源:https://stackoverflow.com/questions/32081303/sqlite-one-to-many-relationship

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!