MVVMCross社区SqLite - 表之间的关系

ste*_*hnx 4 sqlite mvvmcross sqlite-net

我有两个简单的表格如下:

public class MediaPartner
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public string PhoneNumber { get; set; }
    public string CompanyName { get; set; }
    public double Lat { get; set; }
    public double Lng { get; set; }
    public DateTime InsertedUtc { get; set; }
}    

public class ImageGroup
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    public List<MediaPartner> IdMediaPartner { get; set; }
    public string ImagePath { get; set; }
    public bool IsSent { get; set; }
    public DateTime InsertedUtc { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

问题:

public List <MediaPartner> IdMediaPartner {get; 组; }

公共MediaPartner IdMediaPartner {获得; 组; }
不会编译.

我的问题是:有没有办法在这两个表之间建立一对多的关系?

谢谢!

Stu*_*art 6

SQLite-net仅使用索引提供跨表引用,如:

public class Stock
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [MaxLength(8)]
    public string Symbol { get; set; }
}

public class Valuation
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [Indexed]
    public int StockId { get; set; }
    public DateTime Time { get; set; }
    public decimal Price { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

sqlite-net至少有一个扩展,它允许OneToMany声明属性 - 请参阅https://bitbucket.org/twincoders/sqlite-net-extensions,它们可以实现如下代码:

public class Stock
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }
    [MaxLength(8)]
    public string Symbol { get; set; }

    [OneToMany]      // One to many relationship with Valuation
    public List<Valuation> Valuations { get; set; }
}

public class Valuation
{
    [PrimaryKey, AutoIncrement]
    public int Id { get; set; }

    [ForeignKey(typeof(Stock))]     // Specify the foreign key
    public int StockId { get; set; }
    public DateTime Time { get; set; }
    public decimal Price { get; set; }

    [ManyToOne]      // Many to one relationship with Stock
    public Stock Stock { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我不确定这个的确切实现 - 例如我不知道这是否使用真正的FOREIGN KEY约束 - 但代码是开源的,正在积极开发中,内置了mvvmcross插件支持,是跨平台的并且是可用的用于分叉和捐款.