1

I'm playing and Learning EntityFramework 7 RC1.

I have

public class Person
{
  public long PersonId{get;set;}
  public ICollection<Relation> Friends {get;set;}
  public ICollection<Group> Groups{get;set;} //Works if commented
}

public class Relation
{
        public long RelationId { get; set; }
        public long PersonId { get; set; }

        public Person FriendWith { get; set; }

        public ICollection<RelationType> Status { get; set; }
}

public class Group
{
        public long GroupId { get; set; }
        public long PersonId { get; set; }

        public string Name { get; set; }
        public ICollection<Person> Friends { get; set; }
}

Everything works in my model but not the last property of the Group class.

What i want is that a person can have Friends(Person) and can group his friends in groups (coworkers, friends...). The top would be to have the possibility to query a Person and get : - Person.Friends - Person.Groups - Person.Groups.FirstOrDefault().Friends

Thank you very for your help.

Netah
  • 245
  • 4
  • 11
  • What do you meant with not working? Do you get compilation error?, runtime exception? What do they state? – E-Bat Dec 04 '15 at 21:49
  • Looks like a many-to-many relationship. That's a bit odd in EF7, so you'll have to follow the directions at http://stackoverflow.com/questions/29442493/ – JonTheMon Dec 04 '15 at 21:54
  • @E-Bat : The navigation Groups' on entity type 'Person' has not been added to the model, or ignored, or target entityType ignored. – Netah Dec 04 '15 at 22:05
  • @JonTheMon : Is it not a One-to-Many Relationship ? And not between photo and person but person and person – Netah Dec 04 '15 at 22:07
  • 1
    Why do you have a PersonId in the Group? – Kirsten Dec 05 '15 at 10:07
  • @kristen g : as in the ef7 doc (and in Relation). It does not generate any error.The error is Group.Friends. I think i missed Something in the modelBuilder but i don't know what. – Netah Dec 05 '15 at 11:16
  • `Person` has collection navigation `Groups` and `Group` has collection navigation `Friends` so it is many to many relationship. A person can have multiple groups and a group can have multiple persons in it. So you need to configure a join table as in the link posted by @JonTheMon. In the absence of which there will not be any relation between `Person` & `Group` therefore EF throws exception that you have navigation properties in the model which are not added to the model. – Smit Dec 06 '15 at 18:17
  • EF7 doesn't support Many to Many relationships yet. – Vahid Amiri Apr 08 '16 at 21:54
  • 1
    [Same problem is solved in this question](http://stackoverflow.com/questions/34527336/the-navigation-on-entity-type-has-not-been-added-to-the-model-or-ignored-or-en) –  Apr 13 '16 at 07:36

0 Answers0