Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Grandpa
- {
- public Guid Id { get; set; }
- public Father Robert { get; set; }
- public Father Jack { get; set; }
- }
- public class Father
- {
- public Guid Id { get; set; }
- // I use this to reference Grandpa
- public Guid GrandpaId { get; set; }
- public List<Son> MySons { get; set; }
- }
- public class Son
- {
- public Guid Id { get; set; }
- // I use this to reference Father
- public Guid FatherId { get; set; }
- public string Name { get; set; }
- }
- modelBuilder.Entity<Father>()
- .ToTable("Fathers");
- modelBuilder.Entity<Son>()
- .ToTable("Sons");
- modelBuilder.Entity<Grandpa>(g =>
- {
- x.OwnsOne(y => y.Robert, z =>
- {
- z.OwnsMany(a => a.MySons, b =>
- {
- b.HasKey(k=>k.Id);
- b.ToTable("Sons");
- });
- z.ToTable("Fathers");
- });
- x.OwnsOne(y => y.Jack, z =>
- {
- z.OwnsMany(a => a.MySons, b =>
- {
- b.HasKey(k=>k.Id);
- b.ToTable("Sons");
- });
- z.ToTable("Fathers");
- });
- });
- 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