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
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
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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.