sを指定する必要がありますForeignKey
。次のようにしてみてください。不明な点についてはコメントを追加しました。
public class Transaction
{
[Key]
public int TransactionId {get;set;}
public string Username {get;set;}
// Whatever the column is
public int OccasionServiceId {get;set;}
[ForeignKey("OccasionServiceId")] // What on Transaction points to Service's Key
public Service OccasionService {get;set;}
}
public class Service
{
// Ideally this would be called ServiceId instead?
[Key]
public int TransactionId {get;set;}
// If this uses TransactionId then are you sure you don't need a Key that is ServiceId
public Transaction Transaction { get; set; }
[ForeignKey("TransactionId")] // What on ServiceAddon points at Service's Key
public virtual ICollection<ServiceAddon> ServiceAddons { get; set; }
}
public class ServiceAddon
{
[Key]
public int ServiceAddonId { get; set; }
// Don't you need a ServiceId here?
public int TransactionId { get; set; }
public int AddonId { get; set; }
public decimal AddonPrice { get; set; }
public virtual Addon Addon { get; set; }
}
私が作成した場合、私のモデルは次のようになります。
public class Transaction
{
[Key]
public int TransactionId {get;set;}
public string Username {get;set;}
public int ServiceId {get;set;}
[ForeignKey("ServiceId")]
public Service Service {get;set;}
}
public class Service
{
[Key]
public int ServiceId {get;set;}
public int TransactionId {get;set;}
[ForeignKey("TransactionId")
public Transaction Transaction { get; set; }
[ForeignKey("TransactionId")] // What on ServiceAddon points at Service's Key
public virtual ICollection<ServiceAddon> ServiceAddons { get; set; }
}
public class ServiceAddon
{
[Key]
public int ServiceAddonId { get; set; }
public int ServiceId {get;set;}
[ForeignKey("ServiceId")]
public Service Service {get;set;}
}