gpt4 book ai didi

sqlite - MVVMCross Community Sqlite - 表之间的关系

转载 作者:行者123 更新时间:2023-12-03 16:15:39 26 4
gpt4 key购买 nike

我有两个简单的表如下:

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

问题:

public List< MediaPartner > IdMediaPartner { get; set; }
OR
public MediaPartner IdMediaPartner { get; set; }
does not compile.



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

谢谢!

最佳答案

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

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

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

关于sqlite - MVVMCross Community Sqlite - 表之间的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21076420/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com