【问题标题】:Sqlite One to Many RelationshipSqlite 一对多关系
【发布时间】:2015-11-11 21:57:33
【问题描述】:

我目前正在制作一个需要在 sqlite 数据库中存储和获取数据的应用程序。我目前使用的两个 Nuget 包是 Sqlite PCLSQLite-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;}
}

整个东西编译得很好,但是当我尝试运行模拟器时,我收到了这条消息:

System.NotSupportedException 已被抛出 不知道 System.Collections.Generic.List1

我检查了 SQLite-Net Extensions documentation,它确实支持 List。

有谁知道如何解决这个问题?

【问题讨论】:

  • 不起作用,收到相同的消息。谢谢!
  • 我认为他们正在努力(或努力)修复 List 问题。 link

标签: c# list generics xamarin sqlite-net


【解决方案1】:

请在 PatientVitals 表中添加 Patient 的主键作为外键。

【讨论】:

  • 这是公共字符串 SmartCardID。
  • 你必须把[ForeignKey(typeof(PatientItem))]改成[ForeignKey(typeof(Patien))]
【解决方案2】:

无论如何,经过一番研究,结果证明我必须删除所有与 SQLite 相关的小工具,然后将它们重新安装到项目中。在我的例子中,由于我需要 SQLite-Net 扩展,我只需要将它放入我的项目中,任何依赖项轻推也将与 SQL-Net 扩展一起安装。

【讨论】:

    猜你喜欢
    • 2016-10-04
    • 2014-01-29
    • 2015-02-14
    • 2022-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    相关资源
    最近更新 更多