I can't make a simple foreign key relationship in MVC WEB API. I am very confused of how it works. I'm quite confused now after several hours of trying to get this to work.
I have 3 model classes: Task, TaskSubtype and Account
Tasksubtype have a accountID and TaskSubtypeId on creation:
public class Task
{
public int id { get; set; }
[Key]
public Guid TaskId { get; set; }
[ForeignKey("TaskSubType")]
public Guid TaskSubTypeId { get; set; }
[ForeignKey("Account")]
public Guid UserId { get; set; }
}
public class Account
{
public int Id { get; set; }
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid UserId { get; set; }
}
public class TaskSubType
{
public int id { get; set; }
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid SubTaskID { get; set; }
public String Name { get; set; }
}
What have I done wrong?