2014-01-12 51 views
4

我有兩個簡單的表如下關係:MVVMCross社區源碼 - 表

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; } 
} 

問題:

公開名單< MediaPartner> IdMediaPartner {獲得;組; }

public MediaPartner IdMediaPartner {get;組; }
不能編譯。

我的問題是:有沒有辦法建立這兩個表之間的一對多關係?

謝謝!

回答

6

SQLite的網只提供跨表使用索引等引用:

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; } 
} 

有至少一個延伸至SQLITE網,其允許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; } 
} 

我不確定這個的確切實現 - 例如我不知道這是否使用真正的FOREIGN KEY限制 - 但代碼是開源的,正在積極開發,具有mvvmcross插件支持內置,是跨平臺,可用於分叉和貢獻。

+0

謝謝你的回答和MVVMCross! – stephnx