Esempio n. 1
0
        protected virtual void Configure(OwnedNavigationBuilder <Level3, Level4> l4)
        {
            l4.Ignore(e => e.OneToOne_Optional_Self4)
            .Ignore(e => e.OneToMany_Required_Self4)
            .Ignore(e => e.OneToMany_Required_Self_Inverse4)
            .Ignore(e => e.OneToMany_Optional_Self4)
            .Ignore(e => e.OneToMany_Optional_Self_Inverse4);

            l4.Property(e => e.Id).ValueGeneratedNever();

            l4.HasOne(e => e.OneToOne_Optional_PK_Inverse4)
            .WithOne(e => e.OneToOne_Optional_PK3)
            .HasPrincipalKey <Level3>()
            .IsRequired(false);

            l4.HasOne(e => e.OneToOne_Required_FK_Inverse4)
            .WithOne(e => e.OneToOne_Required_FK3)
            .HasForeignKey <Level4>(e => e.Level3_Required_Id)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l4.HasOne(e => e.OneToOne_Optional_FK_Inverse4)
            .WithOne(e => e.OneToOne_Optional_FK3)
            .HasForeignKey <Level4>(e => e.Level3_Optional_Id)
            .IsRequired(false);

            l4.HasOne(e => e.OneToMany_Required_Inverse4)
            .WithMany(e => e.OneToMany_Required3)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l4.HasOne(e => e.OneToMany_Optional_Inverse4)
            .WithMany(e => e.OneToMany_Optional3)
            .IsRequired(false);
        }
        protected virtual void Configure(OwnedNavigationBuilder <Level2, Level3> l3)
        {
            var level3 = l3.Ignore(e => e.OneToOne_Optional_Self3)
                         .Ignore(e => e.OneToMany_Required_Self3)
                         .Ignore(e => e.OneToMany_Required_Self_Inverse3)
                         .Ignore(e => e.OneToMany_Optional_Self3)
                         .Ignore(e => e.OneToMany_Optional_Self_Inverse3)
                         .OwnedEntityType;

            l3.Property(e => e.Id).ValueGeneratedNever();

            l3.HasOne(e => e.OneToOne_Optional_PK_Inverse3)
            .WithOne(e => e.OneToOne_Optional_PK2)
            .HasPrincipalKey <Level2>(e => e.Id)
            .IsRequired(false);

            l3.HasOne(e => e.OneToOne_Required_FK_Inverse3)
            .WithOne(e => e.OneToOne_Required_FK2)
            .HasForeignKey <Level3>(e => e.Level2_Required_Id)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l3.HasOne(e => e.OneToOne_Optional_FK_Inverse3)
            .WithOne(e => e.OneToOne_Optional_FK2)
            .HasForeignKey <Level3>(e => e.Level2_Optional_Id)
            .IsRequired(false);

            l3.HasOne(e => e.OneToMany_Required_Inverse3)
            .WithMany(e => e.OneToMany_Required2)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l3.HasOne(e => e.OneToMany_Optional_Inverse3)
            .WithMany(e => e.OneToMany_Optional2)
            .IsRequired(false);

            ForeignKey level4Fk;
            var        level4 = level3.Model.AddEntityType(
                "Level1.OneToOne_Required_PK1#Level2.OneToOne_Required_PK2#Level3.OneToOne_Required_PK3#Level4",
                typeof(Level4));

            using (var batch = ((Model)level3.Model).ConventionDispatcher.DelayConventions())
            {
                level4Fk          = (ForeignKey)level4.AddForeignKey(level4.FindProperty(nameof(Level4.Id)), level3.FindPrimaryKey(), level3);
                level4Fk.IsUnique = true;
                level4Fk.SetPrincipalToDependent(nameof(Level3.OneToOne_Required_PK3), ConfigurationSource.Explicit);
                level4Fk.SetDependentToPrincipal(nameof(Level4.OneToOne_Required_PK_Inverse4), ConfigurationSource.Explicit);
                level4Fk.DeleteBehavior = DeleteBehavior.Restrict;
                level4Fk = (ForeignKey)batch.Run(level4Fk);
            }

            Configure(new OwnedNavigationBuilder <Level3, Level4>(level4Fk));
        }
Esempio n. 3
0
        protected virtual void Configure(OwnedNavigationBuilder <Level1, Level2> l2)
        {
            var level2 = l2.Ignore(e => e.OneToOne_Optional_Self2)
                         .Ignore(e => e.OneToMany_Required_Self2)
                         .Ignore(e => e.OneToMany_Required_Self_Inverse2)
                         .Ignore(e => e.OneToMany_Optional_Self2)
                         .Ignore(e => e.OneToMany_Optional_Self_Inverse2)
                         .OwnedEntityType;

            l2.Property(e => e.Id).ValueGeneratedNever();

            l2.HasOne(e => e.OneToOne_Optional_PK_Inverse2)
            .WithOne(e => e.OneToOne_Optional_PK1)
            .HasPrincipalKey <Level1>(e => e.Id)
            .IsRequired(false);

            l2.HasOne(e => e.OneToOne_Required_FK_Inverse2)
            .WithOne(e => e.OneToOne_Required_FK1)
            .HasForeignKey <Level2>(e => e.Level1_Required_Id)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l2.HasOne(e => e.OneToOne_Optional_FK_Inverse2)
            .WithOne(e => e.OneToOne_Optional_FK1)
            .HasForeignKey <Level2>(e => e.Level1_Optional_Id)
            .IsRequired(false);

            l2.HasOne(e => e.OneToMany_Required_Inverse2)
            .WithMany(e => e.OneToMany_Required1)
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            l2.HasOne(e => e.OneToMany_Optional_Inverse2)
            .WithMany(e => e.OneToMany_Optional1)
            .IsRequired(false);

            ForeignKey level3Fk;
            var        level3 = level2.Model.AddEntityType(typeof(Level3), nameof(Level2.OneToOne_Required_PK2), level2);

            using (var batch = ((Model)level2.Model).ConventionDispatcher.StartBatch())
            {
                level3Fk          = (ForeignKey)level3.AddForeignKey(level3.FindProperty(nameof(Level3.Id)), level2.FindPrimaryKey(), level2);
                level3Fk.IsUnique = true;
                level3Fk.HasPrincipalToDependent(nameof(Level2.OneToOne_Required_PK2), ConfigurationSource.Explicit);
                level3Fk.HasDependentToPrincipal(nameof(Level3.OneToOne_Required_PK_Inverse3), ConfigurationSource.Explicit);
                level3Fk.DeleteBehavior = DeleteBehavior.Restrict;
                level3Fk = batch.Run(level3Fk);
            }

            Configure(new OwnedNavigationBuilder <Level2, Level3>((EntityType)level2, level3Fk.DeclaringEntityType, level3Fk.Builder));
        }