Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. public class Grandpa
  2. {
  3. public Guid Id { get; set; }
  4. public Father Robert { get; set; }
  5. public Father Jack { get; set; }
  6. }
  7.  
  8. public class Father
  9. {
  10. public Guid Id { get; set; }
  11. // I use this to reference Grandpa
  12. public Guid GrandpaId { get; set; }
  13. public List<Son> MySons { get; set; }
  14. }
  15.  
  16. public class Son
  17. {
  18. public Guid Id { get; set; }
  19. // I use this to reference Father
  20. public Guid FatherId { get; set; }
  21. public string Name { get; set; }
  22. }
  23.  
  24. modelBuilder.Entity<Father>()
  25. .ToTable("Fathers");
  26. modelBuilder.Entity<Son>()
  27. .ToTable("Sons");
  28. modelBuilder.Entity<Grandpa>(g =>
  29. {
  30. x.OwnsOne(y => y.Robert, z =>
  31. {
  32. z.OwnsMany(a => a.MySons, b =>
  33. {
  34. b.HasKey(k=>k.Id);
  35. b.ToTable("Sons");
  36. });
  37. z.ToTable("Fathers");
  38. });
  39. x.OwnsOne(y => y.Jack, z =>
  40. {
  41. z.OwnsMany(a => a.MySons, b =>
  42. {
  43. b.HasKey(k=>k.Id);
  44. b.ToTable("Sons");
  45. });
  46. z.ToTable("Fathers");
  47. });
  48. });
  49.  
  50. Cannot use table 'Fathers' for entity type 'Grandpa.Father#Robert' since it is being used for entity type 'Grandpa.Father#Jack' and there is no relationship between their primary keys.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement