From 609641ab1eefff0c25a1b8378497c90ec5344561 Mon Sep 17 00:00:00 2001 From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Date: Wed, 6 Nov 2024 19:34:25 +0100 Subject: [PATCH] update examples to be more clear/correct --- .../core/Modeling/Relationships/ManyToMany.cs | 116 +++++++++--------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/samples/core/Modeling/Relationships/ManyToMany.cs b/samples/core/Modeling/Relationships/ManyToMany.cs index ac37a5e25f..5ac3fcfa7f 100644 --- a/samples/core/Modeling/Relationships/ManyToMany.cs +++ b/samples/core/Modeling/Relationships/ManyToMany.cs @@ -75,8 +75,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsId").HasPrincipalKey(nameof(Tag.Id)), - r => r.HasOne(typeof(Post)).WithMany().HasForeignKey("PostsId").HasPrincipalKey(nameof(Post.Id)), + r => r.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsId").HasPrincipalKey(nameof(Tag.Id)), + l => l.HasOne(typeof(Post)).WithMany().HasForeignKey("PostsId").HasPrincipalKey(nameof(Post.Id)), j => j.HasKey("PostsId", "TagsId")); } #endregion @@ -142,8 +142,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany() .UsingEntity( "PostTag", - l => l.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsId").HasPrincipalKey(nameof(Tag.Id)), - r => r.HasOne(typeof(Post)).WithMany().HasForeignKey("PostId").HasPrincipalKey(nameof(Post.Id)), + r => r.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsId").HasPrincipalKey(nameof(Tag.Id)), + l => l.HasOne(typeof(Post)).WithMany().HasForeignKey("PostId").HasPrincipalKey(nameof(Post.Id)), j => j.HasKey("PostId", "TagsId")); } #endregion @@ -211,8 +211,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostsToTagsJoinTable", - l => l.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsId").HasPrincipalKey(nameof(Tag.Id)), - r => r.HasOne(typeof(Post)).WithMany().HasForeignKey("PostsId").HasPrincipalKey(nameof(Post.Id)), + r => r.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsId").HasPrincipalKey(nameof(Tag.Id)), + l => l.HasOne(typeof(Post)).WithMany().HasForeignKey("PostsId").HasPrincipalKey(nameof(Post.Id)), j => j.HasKey("PostsId", "TagsId")); } #endregion @@ -269,8 +269,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMany(e => e.Tags) .WithMany(e => e.Posts) .UsingEntity( - l => l.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagForeignKey"), - r => r.HasOne(typeof(Post)).WithMany().HasForeignKey("PostForeignKey")); + r => r.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagForeignKey"), + l => l.HasOne(typeof(Post)).WithMany().HasForeignKey("PostForeignKey")); } #endregion } @@ -285,8 +285,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagForeignKey").HasPrincipalKey(nameof(Tag.Id)), - r => r.HasOne(typeof(Post)).WithMany().HasForeignKey("PostForeignKey").HasPrincipalKey(nameof(Post.Id)), + r => r.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagForeignKey").HasPrincipalKey(nameof(Tag.Id)), + l => l.HasOne(typeof(Post)).WithMany().HasForeignKey("PostForeignKey").HasPrincipalKey(nameof(Post.Id)), j => j.HasKey("PostForeignKey", "TagForeignKey")); } #endregion @@ -380,8 +380,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMany(e => e.Tags) .WithMany(e => e.Posts) .UsingEntity( - l => l.HasOne().WithMany().HasForeignKey(e => e.TagId), - r => r.HasOne().WithMany().HasForeignKey(e => e.PostId)); + r => r.HasOne().WithMany().HasForeignKey(e => e.TagId), + l => l.HasOne().WithMany().HasForeignKey(e => e.PostId)); } #endregion } @@ -396,8 +396,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne().WithMany().HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.Id), - r => r.HasOne().WithMany().HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.Id), + r => r.HasOne().WithMany().HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.Id), + l => l.HasOne().WithMany().HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.Id), j => j.HasKey(e => new { e.PostId, e.TagId })); } #endregion @@ -475,8 +475,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMany(e => e.Tags) .WithMany(e => e.Posts) .UsingEntity( - l => l.HasOne().WithMany(e => e.PostTags), - r => r.HasOne().WithMany(e => e.PostTags)); + r => r.HasOne().WithMany(e => e.PostTags), + l => l.HasOne().WithMany(e => e.PostTags)); } #endregion } @@ -491,8 +491,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.Id), - r => r.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.Id), + r => r.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.Id), + l => l.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.Id), j => j.HasKey(e => new { e.PostId, e.TagId })); } #endregion @@ -572,8 +572,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMany(e => e.Tags) .WithMany(e => e.Posts) .UsingEntity( - l => l.HasOne(e => e.Tag).WithMany(e => e.PostTags), - r => r.HasOne(e => e.Post).WithMany(e => e.PostTags)); + r => r.HasOne(e => e.Tag).WithMany(e => e.PostTags), + l => l.HasOne(e => e.Post).WithMany(e => e.PostTags)); } #endregion } @@ -588,8 +588,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne(e => e.Tag).WithMany(e => e.PostTags).HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.Id), - r => r.HasOne(e => e.Post).WithMany(e => e.PostTags).HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.Id), + r => r.HasOne(e => e.Tag).WithMany(e => e.PostTags).HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.Id), + l => l.HasOne(e => e.Post).WithMany(e => e.PostTags).HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.Id), j => j.HasKey(e => new { e.PostId, e.TagId })); } #endregion @@ -653,8 +653,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMany(e => e.Tags) .WithMany(e => e.Posts) .UsingEntity( - l => l.HasOne(e => e.Tag).WithMany(e => e.PostTags).HasForeignKey(e => e.TagForeignKey), - r => r.HasOne(e => e.Post).WithMany(e => e.PostTags).HasForeignKey(e => e.PostForeignKey)); + r => r.HasOne(e => e.Tag).WithMany(e => e.PostTags).HasForeignKey(e => e.TagForeignKey), + l => l.HasOne(e => e.Post).WithMany(e => e.PostTags).HasForeignKey(e => e.PostForeignKey)); } #endregion } @@ -669,8 +669,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne(e => e.Tag).WithMany(e => e.PostTags).HasForeignKey(e => e.TagForeignKey).HasPrincipalKey(e => e.Id), - r => r.HasOne(e => e.Post).WithMany(e => e.PostTags).HasForeignKey(e => e.PostForeignKey).HasPrincipalKey(e => e.Id), + r => r.HasOne(e => e.Tag).WithMany(e => e.PostTags).HasForeignKey(e => e.TagForeignKey).HasPrincipalKey(e => e.Id), + l => l.HasOne(e => e.Post).WithMany(e => e.PostTags).HasForeignKey(e => e.PostForeignKey).HasPrincipalKey(e => e.Id), j => j.HasKey(e => new { e.PostForeignKey, e.TagForeignKey })); } #endregion @@ -726,8 +726,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMany(e => e.Tags) .WithMany(e => e.Posts) .UsingEntity( - l => l.HasOne(typeof(Tag)).WithMany().HasPrincipalKey(nameof(Tag.AlternateKey)), - r => r.HasOne(typeof(Post)).WithMany().HasPrincipalKey(nameof(Post.AlternateKey))); + r => r.HasOne(typeof(Tag)).WithMany().HasPrincipalKey(nameof(Tag.AlternateKey)), + l => l.HasOne(typeof(Post)).WithMany().HasPrincipalKey(nameof(Post.AlternateKey))); } #endregion } @@ -742,8 +742,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsAlternateKey").HasPrincipalKey(nameof(Tag.AlternateKey)), - r => r.HasOne(typeof(Post)).WithMany().HasForeignKey("PostsAlternateKey").HasPrincipalKey(nameof(Post.AlternateKey)), + r => r.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsAlternateKey").HasPrincipalKey(nameof(Tag.AlternateKey)), + l => l.HasOne(typeof(Post)).WithMany().HasForeignKey("PostsAlternateKey").HasPrincipalKey(nameof(Post.AlternateKey)), j => j.HasKey("PostsAlternateKey", "TagsAlternateKey")); } #endregion @@ -809,8 +809,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMany(e => e.Tags) .WithMany(e => e.Posts) .UsingEntity( - l => l.HasOne(e => e.Tag).WithMany(e => e.PostTags).HasPrincipalKey(e => e.AlternateKey), - r => r.HasOne(e => e.Post).WithMany(e => e.PostTags).HasPrincipalKey(e => e.AlternateKey)); + r => r.HasOne(e => e.Tag).WithMany(e => e.PostTags).HasPrincipalKey(e => e.AlternateKey), + l => l.HasOne(e => e.Post).WithMany(e => e.PostTags).HasPrincipalKey(e => e.AlternateKey)); } #endregion } @@ -825,8 +825,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne(e => e.Tag).WithMany(e => e.PostTags).HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.AlternateKey), - r => r.HasOne(e => e.Post).WithMany(e => e.PostTags).HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.AlternateKey), + r => r.HasOne(e => e.Tag).WithMany(e => e.PostTags).HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.AlternateKey), + l => l.HasOne(e => e.Post).WithMany(e => e.PostTags).HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.AlternateKey), j => j.HasKey(e => new { e.PostId, e.TagId })); } #endregion @@ -901,8 +901,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne().WithMany().HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.Id), - r => r.HasOne().WithMany().HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.Id), + r => r.HasOne().WithMany().HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.Id), + l => l.HasOne().WithMany().HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.Id), j => j.HasKey(e => e.Id)); } #endregion @@ -975,8 +975,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsId").HasPrincipalKey(nameof(Tag.Id)), - r => r.HasOne(typeof(Post)).WithMany().HasForeignKey("PostsId").HasPrincipalKey(nameof(Post.Id)), + r => r.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsId").HasPrincipalKey(nameof(Tag.Id)), + l => l.HasOne(typeof(Post)).WithMany().HasForeignKey("PostsId").HasPrincipalKey(nameof(Post.Id)), j => { j.IndexerProperty("Id"); @@ -1058,8 +1058,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.Id), - r => r.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.Id), + r => r.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.TagId).HasPrincipalKey(e => e.Id), + l => l.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.PostId).HasPrincipalKey(e => e.Id), j => { j.HasKey(e => new { e.PostId, e.TagId }); @@ -1117,8 +1117,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMany(e => e.Tags) .WithMany(e => e.Posts) .UsingEntity( - l => l.HasOne(typeof(Tag)).WithMany().OnDelete(DeleteBehavior.Restrict), - r => r.HasOne(typeof(Post)).WithMany().OnDelete(DeleteBehavior.Restrict)); + r => r.HasOne(typeof(Tag)).WithMany().OnDelete(DeleteBehavior.Restrict), + l => l.HasOne(typeof(Post)).WithMany().OnDelete(DeleteBehavior.Restrict)); } #endregion } @@ -1133,8 +1133,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsId").HasPrincipalKey(nameof(Tag.Id)).OnDelete(DeleteBehavior.Restrict), - r => r.HasOne(typeof(Post)).WithMany().HasForeignKey("PostsId").HasPrincipalKey(nameof(Post.Id)).OnDelete(DeleteBehavior.Restrict), + r => r.HasOne(typeof(Tag)).WithMany().HasForeignKey("TagsId").HasPrincipalKey(nameof(Tag.Id)).OnDelete(DeleteBehavior.Restrict), + l => l.HasOne(typeof(Post)).WithMany().HasForeignKey("PostsId").HasPrincipalKey(nameof(Post.Id)).OnDelete(DeleteBehavior.Restrict), j => j.HasKey("PostsId", "TagsId")); } #endregion @@ -1186,8 +1186,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Parents) .UsingEntity( "PersonPerson", - l => l.HasOne(typeof(Person)).WithMany().HasForeignKey("ChildrenId").HasPrincipalKey(nameof(Person.Id)), - r => r.HasOne(typeof(Person)).WithMany().HasForeignKey("ParentsId").HasPrincipalKey(nameof(Person.Id)), + r => r.HasOne(typeof(Person)).WithMany().HasForeignKey("ChildrenId").HasPrincipalKey(nameof(Person.Id)), + l => l.HasOne(typeof(Person)).WithMany().HasForeignKey("ParentsId").HasPrincipalKey(nameof(Person.Id)), j => j.HasKey("ChildrenId", "ParentsId")); } #endregion @@ -1252,8 +1252,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany() .UsingEntity( "PersonPerson", - l => l.HasOne(typeof(Person)).WithMany().HasForeignKey("FriendsId").HasPrincipalKey(nameof(Person.Id)), - r => r.HasOne(typeof(Person)).WithMany().HasForeignKey("PersonId").HasPrincipalKey(nameof(Person.Id)), + r => r.HasOne(typeof(Person)).WithMany().HasForeignKey("FriendsId").HasPrincipalKey(nameof(Person.Id)), + l => l.HasOne(typeof(Person)).WithMany().HasForeignKey("PersonId").HasPrincipalKey(nameof(Person.Id)), j => j.HasKey("FriendsId", "PersonId")); } #endregion @@ -1333,8 +1333,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.Id1), - r => r.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.Id2), + r => r.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.Id1), + l => l.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.Id2), j => j.Property(e => e.CreatedOn).HasDefaultValueSql("CURRENT_TIMESTAMP")); modelBuilder.Entity() @@ -1342,8 +1342,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Blogs) .UsingEntity( "BlogAuthor", - l => l.HasOne().WithMany(e => e.BlogAuthors).HasForeignKey(e => e.Id1), - r => r.HasOne().WithMany(e => e.BlogAuthors).HasForeignKey(e => e.Id2), + r => r.HasOne().WithMany(e => e.BlogAuthors).HasForeignKey(e => e.Id1), + l => l.HasOne().WithMany(e => e.BlogAuthors).HasForeignKey(e => e.Id2), j => j.Property(e => e.CreatedOn).HasDefaultValueSql("CURRENT_TIMESTAMP")); } #endregion @@ -1359,8 +1359,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Posts) .UsingEntity( "PostTag", - l => l.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.Id1).HasPrincipalKey(e => e.Id), - r => r.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.Id2).HasPrincipalKey(e => e.Id), + r => r.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.Id1).HasPrincipalKey(e => e.Id), + l => l.HasOne().WithMany(e => e.PostTags).HasForeignKey(e => e.Id2).HasPrincipalKey(e => e.Id), j => { j.HasKey(e => new { e.Id1, e.Id2 }); @@ -1372,8 +1372,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(e => e.Blogs) .UsingEntity( "BlogAuthor", - l => l.HasOne().WithMany(e => e.BlogAuthors).HasForeignKey(e => e.Id1).HasPrincipalKey(e => e.Id), - r => r.HasOne().WithMany(e => e.BlogAuthors).HasForeignKey(e => e.Id2).HasPrincipalKey(e => e.Id), + r => r.HasOne().WithMany(e => e.BlogAuthors).HasForeignKey(e => e.Id1).HasPrincipalKey(e => e.Id), + l => l.HasOne().WithMany(e => e.BlogAuthors).HasForeignKey(e => e.Id2).HasPrincipalKey(e => e.Id), j => { j.HasKey(e => new { e.Id1, e.Id2 }); @@ -1489,8 +1489,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMany(e => e.Tags) .WithMany(e => e.Posts) .UsingEntity( - l => l.HasOne(e => e.Tag).WithMany(e => e.PostTags), - r => r.HasOne(e => e.Post).WithMany(e => e.PostTags)); + r => r.HasOne(e => e.Tag).WithMany(e => e.PostTags), + l => l.HasOne(e => e.Post).WithMany(e => e.PostTags)); } } }