主キーの代わりに特定のプロパティを参照する外部キーを指定するにはどうすればよいですか?
たとえば、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 the foreign key
public string StockUUID { get; set; }
public DateTime Time { get; set; }
public decimal Price { get; set; }
[ManyToOne] // Many to one relationship with Stock
public Stock Stock { get; set; }
}