How do I specify a foreign key that references a specific property instead of the primary key?
For example the Stock class has a uuid property. And I want to create a foreign key in the Valuation class that references it using this property.
In the following example the line [ForeignKey(typeof(Stock))] references the ID property of the Stock class, but I need it to reference the UUID property.
How would I do that?
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; }
}