Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Models
- public class People
- {
- public int Id { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public List<Relation> Relations { get; set; }
- }
- public class Relation
- {
- public int Id { get; set; }
- public int ParentPeopleID { get; set; }
- public int ChildPeopleID { get; set; }
- public People People { get; set; }
- }
- //Mapping
- HasRequired(p => p.People).WithMany(p => p.Relations).HasForeignKey(p => p.ParentPeopleID);
- //Calling
- var Peoplelist = MyDbContext.People.Include(p=>p.Relations.Select(r=>r.People)).Where(p=>p.Id==1).ToList();
- //or
- var Peoplelist = MyDbContext.People.Include(p=>p.Relations.Select(r=>r.People)).ToList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement