I have the 2 tables in the picture below and want to add a foreign key relationship between them with the ServiceID being the foreign key
My 2 tables side by side My Database Context
CodePudding user response:
Add the following to ServiceStatistics:
[ForeignKey("ServiceLogRefId")]
public ServiceLog ServiceLog {get; set; }
public int ServiceLogRefId {get; set; }
May be a slight difference in annotation given version (you haven't specified in your question).
CodePudding user response:
your code can like this:
public class LoginLog
{
.
.
.
public int ServiceStateId{ get; set; }
public ServiceState ServiceState{ get; set; }
}
public class ServiceState
{
.
.
.
public ICollection<LoginLog> LoginLogs{ get; set; }
}
also you get all info about relations in this link:Relation in EF