小编Ale*_*tov的帖子

如何在 SQLite-Net 扩展中指定外键属性

如何指定引用特定属性而不是主键的外键?

例如 Stock 类有一个 uuid 属性。我想在使用此属性引用它的 Valuation 类中创建一个外键。

在以下示例中,行 [ForeignKey(typeof(Stock))] 引用 Stock 类的 ID 属性,但我需要它引用 UUID 属性。

我该怎么做?

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

    [OneToMany(CascadeOperations = CascadeOperation.All)]      // 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 …
Run Code Online (Sandbox Code Playgroud)

c# sqlite-net-extensions

4
推荐指数
1
解决办法
8600
查看次数

标签 统计

c# ×1

sqlite-net-extensions ×1