Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.68 KB | None | 0 0
  1. //Models
  2. public class People
  3. {
  4. public int Id { get; set; }
  5. public string FirstName { get; set; }
  6. public string LastName { get; set; }  
  7. public List<Relation> Relations { get; set; }
  8. }
  9.  
  10. public class Relation
  11. {
  12. public int Id { get; set; }
  13. public int ParentPeopleID { get; set; }
  14. public int ChildPeopleID { get; set; }  
  15. public People People { get; set; }
  16. }
  17.  
  18. //Mapping
  19. HasRequired(p => p.People).WithMany(p => p.Relations).HasForeignKey(p => p.ParentPeopleID);
  20.  
  21. //Calling
  22. var Peoplelist = MyDbContext.People.Include(p=>p.Relations.Select(r=>r.People)).Where(p=>p.Id==1).ToList();
  23. //or
  24. var Peoplelist = MyDbContext.People.Include(p=>p.Relations.Select(r=>r.People)).ToList();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement