I have a problem with relationships in ASP.NET MVC. I have two models that have a one to many relationship. On the dependent class), the other class has two fields. I know that the dependent class applies the foreign attribute to establish a relationship. In my dependent class, am unsure if I should use to ForeignKey attributes to point to the other class. This is as per this tutorial on MVC site
Here is a simplified example of my problem.
public class Location {
//Other fields here.
public List<Link> Links{get; set;}
}
// dependent class
public class Link {
//Other fields here...
[ForeignKey("Location")]
public string StartingLocation { get; set;}
[ForeignKey("Location")]
public string EndingLocation { get; set;}
public Location Location { get; set;}
}
Is what am doing on my dependent class legal and if so is it recommended?
Thanks and regards.