I'm trying to come up with a model for managing Person and its Friends.
- A Person has 0-to-many Friends
- A Friend is a Person too - not the same one though
- A Friend can belong one or more Groups
Roughly, the schema looks something like this:
I cannot figure out how to achieve the same with EF Code First. This is what I have so far but this doesn't create the required schema
public class Person
{
public long Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public virtual ICollection<Person> Friends { get; set; } // is this right?
}
public class Friend {
public long Id { get; set; }
public long PersonId { get; set; } // Person whose Friend this guy is
public virtual ICollection<Group> Groups { get; set; }
// other fields
}
public class Group{
public long Id { get; set; }
public string Name { get; set; }
}
Can someone help me figure out this mess?