Well, that might be trivial, but I hope someone can give me a direct answer. Say you have two models in an MVC project, and one model contains a list of the other model. Two models would look something like this:
public class Vehicle { [Key] public int VehicleId { get; set; } public virtual List<Wheel> Wheels { get; set; } } public class Wheel { [Key] public int WheelId { get; set; } [Required] public int VehicleId { get; set;} [Required] public virtual Vehicle { get; set; } }
Now say that you have the same thing, but with only one model. At first I thought it would look something like this:
public class MyClass { [Key] public int MyClassId { get; set; } public string MyData { get; set; } public virtual List<MyClass> MyClasses { get; set; } }
This only throws me off because MyClasses is listed as a navigation property. This would mean that each MyClasses[i] must have a MyClass property and another MyclassId that references the parent MyClass . After thinking about this for a while, I began to feel dizzy. Am I doing it right?
source share