I have an Offer
entity that provides a link between two users in my system.
public class Offer
{
public OfferStatus Status { get; set; }
public decimal Amount {get; set; }
public virtual User Provider { get; set; }
public virtual User Receiver { get; set; }
}
This User
entity has primary key of:
public string Id { get; set; }
I would like to have the two users ID strings appear in the Offer
table like so:
public class Offer
{
public OfferStatus Status { get; set; }
public decimal Amount {get; set; }
public string ProviderId { get; set; }
public string ReceiverId { get; set; }
public virtual User Provider { get; set; }
public virtual User Receiver { get; set; }
}
I have tried:
public class Offer
{
public OfferStatus Status { get; set; }
public decimal Amount {get; set; }
public string ProviderId { get; set; }
public string ReceiverId { get; set; }
[ForeignKey(nameof(ProviderId))]
public virtual User Provider { get; set; }
[ForeignKey(nameof(ReceiverId))]
public virtual User Receiver { get; set; }
}
This is how I usually set foreign keys but usually I only have one of them and I use the naming convention magic that EF provides so I know what I have done here is wrong but I am confused how I am supposed to set their foreign key properties.