Exemple #1
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
            // modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Entity <Models.User>().ToTable("Users", MembershipScheme);
            modelBuilder.Entity <RoleE>().ToTable("Roles", MembershipScheme);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)modelBuilder.Entity <UserRole>(),
                                                          "UserRoles", MembershipScheme);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)modelBuilder.Entity <UserClaim>(),
                                                          "UserClaims", MembershipScheme);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)modelBuilder.Entity <UserLogin>(),
                                                          "UserLogins", MembershipScheme);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)modelBuilder.Entity <RoleClaim>(),
                                                          "RoleClaims", MembershipScheme);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)modelBuilder.Entity <UserToken>(),
                                                          "UserTokens", MembershipScheme);

            modelBuilder.Entity <Sex>()
            .ToTable("Sexes", UserScheme);
            foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
            {
                relationship.DeleteBehavior = DeleteBehavior.Restrict;
            }
            base.OnModelCreating(modelBuilder);
        }
Exemple #2
0
        public void Configure(EntityTypeBuilder <Domain.Entity.S7.BlockArea> blockAreaConfiguration)
        {
            //RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder) blockAreaConfiguration, "S7BlockArea", DatabaseContext.DefaultSchema);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)blockAreaConfiguration, "S7BlockArea");

            blockAreaConfiguration.HasKey(k => k.Id);
            blockAreaConfiguration.Property(p => p.Id).ValueGeneratedOnAdd().IsRequired();

            blockAreaConfiguration.HasIndex(i => i.Name).IsUnique();
            blockAreaConfiguration.Property(p => p.Name).HasMaxLength(50).IsRequired();

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)blockAreaConfiguration.HasOne(c => c.Area).WithMany(cc => cc.S7BlockAreas)
                                                                    .HasForeignKey(fk => fk.AreaId), "ForeignKey_S7BlockArea_Area");
            //.IsRequired();

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)blockAreaConfiguration.HasOne(c => c.WordLen).WithMany(cc => cc.S7BlockAreas)
                                                                    .HasForeignKey(fk => fk.WordLenId), "ForeignKey_S7BlockArea_WordLen");
            //.IsRequired();

            //blockAreaConfiguration.Property(p => p.Name).HasMaxLength(50).IsRequired();

            //blockAreaConfiguration.Property(p => p.Mean).HasMaxLength(50).IsRequired();

            //var tagNavigation = blockAreaConfiguration.Metadata.FindNavigation(nameof(Domain.Db.Entity.S7.Area.S7Tags));
            //var blockAreaNavigation = blockAreaConfiguration.Metadata.FindNavigation(nameof(Domain.Db.Entity.S7.Area.S7BlockAreas));

            //tagNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
            //blockAreaNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
        public void Configure(EntityTypeBuilder <Domain.Entity.View.Common.TagGroupReady> tagGroupReadyConfiguration)
        {
            //RelationalEntityTypeBuilderExtensions.ToView((EntityTypeBuilder) tagGroupReadyConfiguration, "TagGroupReadyView", KSociety.Base.Infra.Shared.Class.DatabaseContext.DefaultSchema);
            RelationalEntityTypeBuilderExtensions.ToView((EntityTypeBuilder)tagGroupReadyConfiguration, "TagGroupReadyView");

            tagGroupReadyConfiguration.HasNoKey();
        }
        public override void Map(EntityTypeBuilder <StreamStatus> builder)
        {
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)builder, "StreamStatuses");

            builder.Property(t => t.StreamStatusId).HasColumnName("StreamStatusId").IsRequired();
            builder.Property(t => t.BroadcasterUsername).HasColumnName("BroadcasterUsername").IsRequired();
            builder.Property(t => t.IsOnline).HasColumnName("IsOnline").IsRequired();
        }
        public override void Map(EntityTypeBuilder <SongRequest> builder)
        {
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)builder, "SongRequests");

            builder.Property(t => t.SongRequestId).HasColumnName("SongRequestId").IsRequired();
            builder.Property(t => t.SongId).HasColumnName("SongId").IsRequired();
            builder.Property(t => t.RequestUsername).HasColumnName("RequestUsername").HasMaxLength(255).IsRequired();

            //builder.HasOne(t => t.Song).WithMany(o => o.SongRequests).HasForeignKey(k => k.SongId);
        }
Exemple #6
0
        public override void Map(EntityTypeBuilder <SongGuessingRecord> builder)
        {
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)builder, "SongGuessingRecord");

            builder.Property(t => t.SongGuessingRecordId).HasColumnName("SongGuessingRecordId").IsRequired();
            builder.Property(t => t.SongDetails).HasColumnName("SongDetails").IsRequired();
            builder.Property(t => t.UsersCanGuess).HasColumnName("UsersCanGuess").IsRequired();
            builder.Property(t => t.IsInProgress).HasColumnName("IsInProgress").IsRequired();
            builder.Property(t => t.FinalPercentage).HasColumnName("FinalPercentage");
        }
        public void Configure(EntityTypeBuilder <Website> websiteConfiguration)
        {
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)websiteConfiguration, "websites");

            websiteConfiguration.HasKey(w => w.Id);
            websiteConfiguration.HasOne(w => w.Image);
            websiteConfiguration.HasMany(x => x.Categories);

            websiteConfiguration.Property(w => w.Name).IsRequired();
            websiteConfiguration.HasIndex(w => w.Url).IsUnique();
            websiteConfiguration.Property(w => w.Email).IsRequired();
            websiteConfiguration.Property(w => w.Password).IsRequired();
        }
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)builder.Entity <User>(), "User");
            builder.Entity <IdentityUserRole <string> >().ToTable("UserRole");
            builder.Entity <IdentityRole>().ToTable("Roles");
            builder.Entity <UserDetail>().ToTable("UserDetail");
            builder.Entity <UserLocation>().ToTable("UserLocation");

            builder.Entity <UserSport>().ToTable("UserSport");
            builder.Entity <UserInterest>().ToTable("UserInterest");
        }
        public override void Map(EntityTypeBuilder <SongPercentageGuess> builder)
        {
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)builder, "SongPercentageGuess");

            builder.Property(t => t.SongPercentageGuessId).HasColumnName("SongPercentageGuessId").IsRequired();
            builder.Property(t => t.SongGuessingRecordId).HasColumnName("SongGuessingRecordId").IsRequired();
            builder.Property(t => t.Username).HasColumnName("Username").IsRequired();
            builder.Property(t => t.Guess).HasColumnName("Guess").IsRequired();

            builder.HasOne(pg => pg.SongGuessingRecord)
            .WithMany(sg => sg.SongPercentageGuesses)
            .HasForeignKey(pg => pg.SongGuessingRecordId);
        }
Exemple #10
0
        public void Configure(EntityTypeBuilder <Domain.Entity.Common.AnalogDigital> analogDigitalConfiguration)
        {
            //RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)analogDigitalConfiguration, "AnalogDigital", DatabaseContext.DefaultSchema);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)analogDigitalConfiguration, "AnalogDigital");

            analogDigitalConfiguration.HasKey(k => k.AnalogDigitalSignal);
            analogDigitalConfiguration.Property(p => p.AnalogDigitalSignal).ValueGeneratedNever().HasMaxLength(7).IsRequired();

            var analogDigitalNavigation = analogDigitalConfiguration
                                          .Metadata.FindNavigation(nameof(Domain.Entity.Common.AnalogDigital.Tags));

            analogDigitalNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
Exemple #11
0
        public void Configure(EntityTypeBuilder <CatalogBrand> builder)
        {
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)builder, "CatalogBrand");

            builder.HasKey(ci => ci.Id);

            builder.Property(ci => ci.Id)
            .ForSqlServerUseSequenceHiLo("catalog_brand_hilo")
            .IsRequired();

            builder.Property(cb => cb.Brand)
            .IsRequired()
            .HasMaxLength(100);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity <Coach>(entity =>
            {
                entity.Property(e => e.Id).ValueGeneratedNever();

                entity.Property(e => e.FirstName)
                .IsRequired()
                .HasMaxLength(50)
                .IsUnicode(false);

                entity.Property(e => e.LastName)
                .IsRequired()
                .HasMaxLength(50)
                .IsUnicode(false);

                RelationalReferenceCollectionBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)entity.HasOne(d => d.Location)
                                                                                 .WithMany(p => p.Coach)
                                                                                 .HasForeignKey(d => d.LocationId)
                                                                                 .OnDelete(DeleteBehavior.ClientSetNull), "FK_Coach_Location");
            });

            modelBuilder.Entity <Location>(entity =>
            {
                RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)entity, "Location", "pwso");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Name)
                .HasMaxLength(25)
                .IsUnicode(false);

                RelationalReferenceCollectionBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)entity.HasOne(d => d.Sport)
                                                                                 .WithMany(p => p.Location)
                                                                                 .HasForeignKey(d => d.SportId)
                                                                                 .OnDelete(DeleteBehavior.ClientSetNull), "FK_Location_Sport");
            });

            modelBuilder.Entity <Sport>(entity =>
            {
                RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)entity, "Sport", "pwso");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Name)
                .IsRequired()
                .HasMaxLength(25)
                .IsUnicode(false);
            });
        }
Exemple #13
0
        public void Configure(EntityTypeBuilder <Domain.Entity.S7.ConnectionType> connectionTypeConfiguration)
        {
            //RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder) connectionTypeConfiguration, "S7ConnectionType", DatabaseContext.DefaultSchema);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)connectionTypeConfiguration, "S7ConnectionType");

            connectionTypeConfiguration.HasKey(k => k.Id);
            connectionTypeConfiguration.Property(p => p.Id).ValueGeneratedNever().IsRequired();

            connectionTypeConfiguration.HasIndex(i => i.Name).IsUnique();
            connectionTypeConfiguration.Property(p => p.Name).HasMaxLength(9).IsRequired();

            var connectionNavigation = connectionTypeConfiguration.Metadata.FindNavigation(nameof(Domain.Entity.S7.ConnectionType.Connections));

            connectionNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
        public void Configure(EntityTypeBuilder <SmoothConfiguration> builder)
        {
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)builder, "SmoothConfigurations");

            builder.HasKey(x => x.Id);

            builder.Property(x => x.Version).IsRequired();
            builder.Property(x => x.ExternalCampaignRefsToExclude).AsDelimitedString().IsRequired();

            builder.HasOne(x => x.DiagnosticConfiguration).WithOne()
            .HasForeignKey <SmoothDiagnosticConfiguration>(x => x.SmoothConfigurationId);

            builder.HasMany(x => x.Passes).WithOne().HasForeignKey(x => x.SmoothConfigurationId);
            builder.HasMany(x => x.IterationRecords).WithOne().HasForeignKey(x => x.SmoothConfigurationId);
            builder.HasMany(x => x.BestBreakFactorGroupRecords).WithOne().HasForeignKey(x => x.SmoothConfigurationId);
        }
Exemple #15
0
        public void Configure(EntityTypeBuilder <Domain.Entity.Common.Bit> bitConfiguration)
        {
            //RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder) bitConfiguration, "Bit", DatabaseContext.DefaultSchema);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)bitConfiguration, "Bit");

            bitConfiguration.HasKey(k => k.BitOfByte);
            bitConfiguration.Property(p => p.BitOfByte).ValueGeneratedNever().IsRequired();

            bitConfiguration.HasIndex(i => i.BitName).IsUnique();
            bitConfiguration.Property(p => p.BitName).HasMaxLength(5).IsRequired();

            var bitNavigation = bitConfiguration
                                .Metadata.FindNavigation(nameof(Domain.Entity.Common.Bit.S7Tags));

            bitNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
Exemple #16
0
        public void Configure(EntityTypeBuilder <Domain.Entity.Common.InOut> inOutConfiguration)
        {
            //RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)inOutConfiguration, "InOut", DatabaseContext.DefaultSchema);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)inOutConfiguration, "InOut");


            inOutConfiguration.HasKey(k => k.InputOutput);
            inOutConfiguration.Property(p => p.InputOutput).ValueGeneratedNever().HasMaxLength(2).IsRequired();

            inOutConfiguration.HasIndex(i => i.InputOutputName).IsUnique();
            inOutConfiguration.Property(p => p.InputOutputName).HasMaxLength(10).IsRequired();

            var inOutNavigation = inOutConfiguration
                                  .Metadata.FindNavigation(nameof(Domain.Entity.Common.InOut.Tags));

            inOutNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
Exemple #17
0
        /// <summary>
        /// 设置表名和Schema [Set the table name and Schema]
        /// 优先级:
        /// * 传入的 tableName 和 schema
        /// * 实体标记的 TableAttribute
        /// * 实体名称, schema 不设置
        /// </summary>
        /// <param name="builder"></param>
        /// <param name="tableName"></param>
        /// <param name="schema"></param>
        /// <returns></returns>
        public static EntityTypeBuilder SetTableName(
            this EntityTypeBuilder builder,
            string tableName = null,
            string schema    = null)
        {
            if (!string.IsNullOrWhiteSpace(tableName))
            {
                return(RelationalEntityTypeBuilderExtensions.ToTable(builder, C(tableName), C(schema)));
            }

            var tableAttr = builder.Metadata.ClrType.GetTableAttribute();

            if (tableAttr != null)
            {
                return(RelationalEntityTypeBuilderExtensions.ToTable(builder, C(tableAttr.Name), C(tableAttr.Schema)));
            }
            return(RelationalEntityTypeBuilderExtensions.ToTable(builder, C(builder.Metadata.ClrType.Name)));
        }
Exemple #18
0
        public void Configure(EntityTypeBuilder <Domain.Entity.S7.WordLen> wordLenConfiguration)
        {
            //RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder) wordLenConfiguration, "S7WordLen", DatabaseContext.DefaultSchema);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)wordLenConfiguration, "S7WordLen");

            wordLenConfiguration.HasKey(k => k.Id); //.HasMaxLength(12);
            wordLenConfiguration.Property(p => p.Id).ValueGeneratedNever().IsRequired();

            wordLenConfiguration.HasIndex(i => i.WordLenName).IsUnique();
            wordLenConfiguration.Property(p => p.WordLenName).HasMaxLength(12).IsRequired();

            wordLenConfiguration.Property(p => p.Mean).HasMaxLength(50).IsRequired();

            var tagNavigation       = wordLenConfiguration.Metadata.FindNavigation(nameof(Domain.Entity.S7.WordLen.S7Tags));
            var blockAreaNavigation = wordLenConfiguration.Metadata.FindNavigation(nameof(Domain.Entity.S7.WordLen.S7BlockAreas));

            tagNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
            blockAreaNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
Exemple #19
0
        public void Configure(EntityTypeBuilder <UserAccount> builder)
        {
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)builder, "UserAccount", _schema);
            builder.HasKey(x => x.Id);


            builder.Property(x => x.Id).HasColumnName("Id").HasColumnType("int").IsRequired().UseIdentityColumn();

            builder.Property(x => x.UserName).HasColumnName("UserName").HasColumnType("nvarchar").HasMaxLength(128).IsRequired();

            builder.Property(x => x.Title).HasColumnName("Title").HasColumnType("nvarchar").HasMaxLength(128).IsRequired();

            builder.Property(x => x.Password).HasColumnName("Password").HasColumnType("varchar").HasMaxLength(256).IsRequired();

            builder.Property(x => x.IsActive).HasColumnName("IsActive").HasColumnType("bit").IsRequired();

            builder.Property(x => x.CreateBy).HasColumnName("CreateBy").HasColumnType("int");

            ConfigurePartial(builder);
        }
Exemple #20
0
        public void Configure(EntityTypeBuilder <Domain.Entity.Common.TagGroup> tagGroupConfiguration)
        {
            //RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder) tagGroupConfiguration, "TagGroup", DatabaseContext.DefaultSchema);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)tagGroupConfiguration, "TagGroup");

            tagGroupConfiguration.HasKey(k => k.Id);
            tagGroupConfiguration.Property(p => p.Id).ValueGeneratedOnAdd().IsRequired();

            tagGroupConfiguration.HasIndex(i => i.Name).IsUnique();
            tagGroupConfiguration.Property(p => p.Name).HasMaxLength(50).IsRequired();

            tagGroupConfiguration.Property(p => p.Clock).IsRequired();

            tagGroupConfiguration.Property(p => p.Update).IsRequired();

            tagGroupConfiguration.Property(p => p.Enable).IsRequired();

            var tagGroupNavigation = tagGroupConfiguration
                                     .Metadata.FindNavigation(nameof(Domain.Entity.Common.TagGroup.Tags));

            tagGroupNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
        public void Configure(EntityTypeBuilder <CatalogItem> builder)
        {
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)builder, "Catalog");

            builder.Property(ci => ci.Id)
            .ForSqlServerUseSequenceHiLo("catalog_hilo")
            .IsRequired();

            builder.Property(ci => ci.Name)
            .IsRequired(true)
            .HasMaxLength(50);

            builder.Property(ci => ci.Price)
            .IsRequired(true);

            builder.HasOne(ci => ci.CatalogBrand)
            .WithMany()
            .HasForeignKey(ci => ci.CatalogBrandId);

            builder.HasOne(ci => ci.CatalogType)
            .WithMany()
            .HasForeignKey(ci => ci.CatalogTypeId);
        }
Exemple #22
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);



            //zmiana nazw tabel z domyślnych na ładniejsze
            modelBuilder.Entity <User>(i =>
            {
                RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)i, "Users");
                i.HasKey(x => x.Id);
            });
            modelBuilder.Entity <Role>(i =>
            {
                RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)i, "Role");
                i.HasKey(x => x.Id);
            });
            modelBuilder.Entity <IdentityUserRole <int> >(i =>
            {
                i.ToTable("UserRole");
                i.HasKey(x => new { x.RoleId, x.UserId });
            });
            modelBuilder.Entity <IdentityUserLogin <int> >(i =>
            {
                i.ToTable("UserLogin");
                i.HasKey(x => new { x.ProviderKey, x.LoginProvider });
            });
            modelBuilder.Entity <IdentityRoleClaim <int> >(i =>
            {
                i.ToTable("RoleClaims");
                i.HasKey(x => x.Id);
            });
            modelBuilder.Entity <IdentityUserClaim <int> >(i =>
            {
                i.ToTable("UserClaims");
                i.HasKey(x => x.Id);
            });


            modelBuilder.Entity <Product>(c =>
            {
                c.Property(p => p.Id)
                .ValueGeneratedOnAdd();
            });

            //modelBuilder.Entity<User>()
            //.HasMany(c => c.Orders)
            //.WithOne(e => e.User)
            //.HasForeignKey(s => s.UserId);



            modelBuilder.Entity <OrderProduct>()
            .HasKey(x => new { x.StockId, x.OrderId });


            //Dodanie płci do tabeli Gender
            modelBuilder.Entity <Gender>()
            .HasData(
                new Gender
            {
                Id   = 1,
                Name = "Mężczyzna"
            },
                new Gender
            {
                Id   = 2,
                Name = "Kobieta"
            },
                new Gender
            {
                Id   = 3,
                Name = "Nieznany"
            }
                );



            //Dodanie roli do tabeli Role
            modelBuilder.Entity <Role>()
            .HasData(
                new Role
            {
                Id             = 1,
                Name           = "Admin",
                NormalizedName = "ADMIN"
            },
                new Role
            {
                Id             = 2,
                Name           = "User",
                NormalizedName = "USER"
            }
                );



            //Dodanie płci do tabeli Sex
            modelBuilder.Entity <Sex>()
            .HasData(
                new Gender
            {
                Id   = 1,
                Name = "Mężczyzna"
            },
                new Gender
            {
                Id   = 2,
                Name = "Kobieta"
            },
                new Gender
            {
                Id   = 3,
                Name = "Unisex"
            }
                );

            //Dodanie typów do tabeli Type
            modelBuilder.Entity <Category>()
            .HasData(
                new Category
            {
                Id   = 1,
                Name = "Obuwie"
            },
                new Category
            {
                Id   = 2,
                Name = "Odzież"
            }
                );


            //Dodanie marek do tabeli Brand
            modelBuilder.Entity <Brand>()
            .HasData(
                new Brand
            {
                Id        = 1,
                Name      = "Jordan",
                PhotoPath = "jordan.png"
            },
                new Brand
            {
                Id        = 2,
                Name      = "Adidas",
                PhotoPath = "adidas.png"
            },
                new Brand
            {
                Id        = 3,
                Name      = "Nike",
                PhotoPath = "nike.png"
            },
                new Brand
            {
                Id        = 4,
                Name      = "Supreme",
                PhotoPath = "supreme.png"
            }
                );

            //Dodanie kolorów do tabeli Color
            modelBuilder.Entity <Color>()
            .HasData(
                new Color
            {
                Id   = 1,
                Name = "Biały"
            },
                new Color
            {
                Id   = 2,
                Name = "Czarny"
            },
                new Color
            {
                Id   = 3,
                Name = "Niebieski"
            },
                new Color
            {
                Id   = 4,
                Name = "Żółty"
            },
                new Color
            {
                Id   = 5,
                Name = "Szary"
            },
                new Color
            {
                Id   = 7,
                Name = "Inny"
            },
                new Color
            {
                Id   = 6,
                Name = "Czerwony"
            }
                );


            // Dodanie przykładowych produktów do tabeli Products
            modelBuilder.Entity <Product>()
            .HasData(
                new Product
            {
                Id          = 1,
                BrandId     = 3,
                ColorId     = 2,
                SexId       = 3,
                CategoryId  = 1,
                Name        = "Air Max 97",
                Price       = 399.99m,
                Description = "But z 97 roku!",
                PhotoPath   = "nikeairmax97.png"
            },
                new Product
            {
                Id          = 2,
                BrandId     = 3,
                ColorId     = 1,
                SexId       = 1,
                CategoryId  = 1,
                Name        = "Cortez",
                Price       = 199.99m,
                Description = "Klasyk noszony przez Forresta Gumpa!",
                PhotoPath   = "nikecortez.png"
            },
                new Product
            {
                Id          = 3,
                BrandId     = 1,
                ColorId     = 6,
                SexId       = 2,
                CategoryId  = 1,
                Name        = "30",
                Price       = 599.99m,
                Description = "Kolejny model butów od najlepszego koszykarza w historii!",
                PhotoPath   = "jordan30.png"
            },
                new Product
            {
                Id          = 4,
                BrandId     = 4,
                ColorId     = 6,
                SexId       = 1,
                CategoryId  = 2,
                Name        = "Bogo Red",
                Price       = 999.99m,
                Description = "Najpopularnieszy model bluzy Supreme!",
                PhotoPath   = "bogored.png"
            },
                new Product
            {
                Id          = 5,
                BrandId     = 4,
                ColorId     = 1,
                SexId       = 1,
                CategoryId  = 2,
                Name        = "Buju Banton Tee",
                Price       = 599.99m,
                Description = "Świetny T-Shirt od Supreme!",
                PhotoPath   = "bujubanton.png"
            },
                new Product
            {
                Id          = 6,
                BrandId     = 4,
                ColorId     = 1,
                SexId       = 3,
                CategoryId  = 2,
                Name        = "Camp Cap",
                Price       = 199.99m,
                Description = "Czarna czapka od Supreme!",
                PhotoPath   = "supremecapblack.png"
            },
                new Product
            {
                Id          = 7,
                BrandId     = 2,
                ColorId     = 1,
                SexId       = 2,
                CategoryId  = 1,
                Name        = "Neo White",
                Price       = 299.99m,
                Description = "Białe adidasy od Adidasa!",
                PhotoPath   = "adidasneowhite.png"
            }

                );

            //Dodanie marek do tabeli Brand
            modelBuilder.Entity <Stock>()
            .HasData(
                new Stock
            {
                ProductId            = 1,
                Id                   = 1,
                IsLastElementOrdered = false,
                Name                 = "10",
                Qty                  = 3
            },
                new Stock
            {
                ProductId            = 1,
                Id                   = 2,
                IsLastElementOrdered = false,
                Name                 = "11",
                Qty                  = 2
            },
                new Stock
            {
                ProductId            = 1,
                Id                   = 3,
                IsLastElementOrdered = false,
                Name                 = "12",
                Qty                  = 1
            },
                new Stock
            {
                ProductId            = 4,
                Id                   = 4,
                IsLastElementOrdered = false,
                Name                 = "S",
                Qty                  = 2
            },
                new Stock
            {
                ProductId            = 4,
                Id                   = 5,
                IsLastElementOrdered = false,
                Name                 = "L",
                Qty                  = 2
            },
                new Stock
            {
                ProductId            = 4,
                Id                   = 6,
                IsLastElementOrdered = false,
                Name                 = "XL",
                Qty                  = 1
            },
                new Stock
            {
                ProductId            = 7,
                Id                   = 7,
                IsLastElementOrdered = false,
                Name                 = "9",
                Qty                  = 1
            },
                new Stock
            {
                ProductId            = 2,
                Id                   = 8,
                IsLastElementOrdered = false,
                Name                 = "11",
                Qty                  = 3
            }
                );


            User adminUser = new User
            {
                UserName             = "******",
                Email                = "*****@*****.**",
                NormalizedEmail      = "*****@*****.**".ToUpper(),
                NormalizedUserName   = "******".ToUpper(),
                TwoFactorEnabled     = false,
                EmailConfirmed       = true,
                PhoneNumber          = "123456789",
                PhoneNumberConfirmed = false,
                City          = "admin",
                FirstName     = "admin",
                LastName      = "admin",
                GenderId      = 3,
                Address1      = "admin",
                PostCode      = "51-627",
                Id            = 1,
                SecurityStamp = Guid.NewGuid().ToString()
            };

            User user = new User
            {
                UserName             = "******",
                Email                = "*****@*****.**",
                NormalizedEmail      = "*****@*****.**".ToUpper(),
                NormalizedUserName   = "******".ToUpper(),
                TwoFactorEnabled     = false,
                EmailConfirmed       = true,
                PhoneNumber          = "987654321",
                PhoneNumberConfirmed = false,
                City          = "user",
                FirstName     = "user",
                LastName      = "user",
                GenderId      = 1,
                Address1      = "user",
                PostCode      = "51-627",
                Id            = 2,
                SecurityStamp = Guid.NewGuid().ToString()
            };


            PasswordHasher <User> ph = new PasswordHasher <User>();

            adminUser.PasswordHash = ph.HashPassword(adminUser, "admin");
            user.PasswordHash      = ph.HashPassword(user, "user");

            var adminrole = new IdentityUserRole <int>
            {
                RoleId = 1, UserId = 1
            };
            var userrole = new IdentityUserRole <int>
            {
                RoleId = 2, UserId = 2
            };

            modelBuilder.Entity <User>().HasData(
                adminUser,
                user
                );

            modelBuilder.Entity <IdentityUserRole <int> >().HasData(
                adminrole,
                userrole
                );
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //todo: how to remove cascade delete
            //   modelBuilder.Conventions.Remove<ManyToManyCascadeDeleteConvention>();
            //   modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();
            modelBuilder.Entity <Models.User>().ToTable("Users", MembershipScheme);
            modelBuilder.Entity <RoleE>().ToTable("Roles", MembershipScheme);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)modelBuilder.Entity <Models.UserRole>(), "UserRoles", MembershipScheme);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)modelBuilder.Entity <UserClaim>(), "UserClaims", MembershipScheme);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)modelBuilder.Entity <UserLogin>(), "UserLogins", MembershipScheme);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)modelBuilder.Entity <RoleClaim>(), "RoleClaims", MembershipScheme);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)modelBuilder.Entity <UserToken>(), "UserTokens", MembershipScheme);

            modelBuilder.Entity <UserSkill>()
            .ToTable("UserSkills", UserScheme)
            .HasKey(it => new { it.UserId, it.SkillId });
            modelBuilder.Entity <ContactPhone>()
            .ToTable("ContactPhones", UserScheme)
            .HasKey(it => new { it.ContactId, it.PhoneId });
            modelBuilder.Entity <UserHobby>()
            .ToTable("UserHobbies", UserScheme)
            .HasKey(it => new { it.UserId, it.HobbyId });
            modelBuilder.Entity <Hobby>()
            .ToTable("Hobbies", UserScheme);
            modelBuilder.Entity <Phone>()
            .ToTable("Phones", UserScheme);
            modelBuilder.Entity <PhoneType>()
            .ToTable("PhoneTypes", UserScheme);
            modelBuilder.Entity <Cont>()
            .ToTable("Contacts", UserScheme);
            modelBuilder.Entity <Sex>()
            .ToTable("Sexes", UserScheme);
            modelBuilder.Entity <UserContact>()
            .ToTable("UserContacts", UserScheme)
            .HasKey(it => new { it.UserId, it.ContactId });
            modelBuilder.Entity <ContactAddress>()
            .ToTable("ContactAddresses", UserScheme)
            .HasKey(it => new { it.ContactId, it.AddressId });
            modelBuilder.Entity <FeedBackComment>()
            .ToTable("FeedBacks", UserScheme);


            modelBuilder.Entity <Address>()
            .ToTable("Addresses", LocationScheme);
            modelBuilder.Entity <Subway>()
            .ToTable("Subways", LocationScheme);
            modelBuilder.Entity <House>()
            .ToTable("Houses", LocationScheme);
            modelBuilder.Entity <Country>()
            .ToTable("Countries", LocationScheme);
            modelBuilder.Entity <City>()
            .ToTable("Cities", LocationScheme);
            modelBuilder.Entity <Street>()
            .ToTable("Streets", LocationScheme);
            modelBuilder.Entity <Flat>()
            .ToTable("Flats", LocationScheme);
            modelBuilder.Entity <Housing>()
            .ToTable("Housings", LocationScheme);
            foreach (var relationship in modelBuilder.Model.GetEntityTypes().SelectMany(e => e.GetForeignKeys()))
            {
                relationship.DeleteBehavior = DeleteBehavior.Restrict;
            }
            base.OnModelCreating(modelBuilder);
        }
Exemple #24
0
        public void Configure(EntityTypeBuilder <Domain.Entity.Common.Connection> connectionConfiguration)
        {
            //try
            //{
            //RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder) connectionConfiguration, "Connection", DatabaseContext.DefaultSchema);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)connectionConfiguration, "Connection");

            connectionConfiguration.HasKey(k => k.Id);
            connectionConfiguration.Property(p => p.Id).ValueGeneratedOnAdd().IsRequired();

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)connectionConfiguration.HasOne(c => c.AutomationType)
                                                                    .WithMany(cc => cc.Connections)
                                                                    .HasForeignKey(fk => fk.AutomationTypeId), "ForeignKey_Connection_AutomationType")
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            connectionConfiguration.HasDiscriminator(connection => connection.AutomationTypeId)
            .HasValue <Domain.Entity.Common.Connection>(0)
            .HasValue <Domain.Entity.S7.S7Connection>(1)
            .HasValue <Domain.Entity.Logix.LogixConnection>(2)
            .HasValue <Domain.Entity.Modbus.ModbusConnection>(3)
            .HasValue <Domain.Entity.Tcp.TcpConnection>(4);



            connectionConfiguration.HasIndex(i => new { i.Name, i.AutomationTypeId }).IsUnique();
            connectionConfiguration.Property(p => p.Name).HasMaxLength(50).IsRequired();

            connectionConfiguration.Property(p => p.Ip).HasMaxLength(15).IsRequired();

            //connectionConfiguration.Property(p => p.Rack).IsRequired();

            //connectionConfiguration.Property(p => p.Slot).IsRequired();

            //connectionConfiguration.HasOne(c => c.ConnectionType).WithMany(cc => cc.Connections)
            //    .HasForeignKey(fk => fk.ConnectionTypeId).HasConstraintName("ForeignKey_S7Connection_S7ConnectionType")
            //    .IsRequired();

            //connectionConfiguration.Property(p => p.RequestedId).IsRequired();

            connectionConfiguration.Property(p => p.Enable).IsRequired();

            connectionConfiguration.Property(p => p.WriteEnable).IsRequired();

            //var s7ConnectionNavigation = connectionConfiguration
            //    .Metadata.FindNavigation(nameof(Domain.Com.Entity.Common.Connection.S7Connections));

            //connectionConfiguration
            //    .HasOne(s7C => s7C.S7Connection)
            //    .WithOne(c => c.StdConnection)
            //    .HasForeignKey<Domain.Com.Entity.S7.Connection>(c => c.StdConnectionId)
            //    .HasConstraintName("ForeignKey_Connection_S7Connection")
            //    .IsRequired();

            //var allenBradleyConnectionNavigation = connectionConfiguration
            //    .Metadata.FindNavigation(nameof(Domain.Com.Entity.Common.Connection.LogixConnections));

            //connectionConfiguration
            //    .HasOne(logixC => logixC.LogixConnection)
            //    .WithOne(c => c.StdConnection)
            //    .HasForeignKey<Domain.Com.Entity.Logix.Connection>(c => c.StdConnectionId)
            //    .HasConstraintName("ForeignKey_Connection_LogixConnection")
            //    .IsRequired();

            var tagNavigation = connectionConfiguration
                                .Metadata.FindNavigation(nameof(Domain.Entity.Common.Connection.Tags));

            //s7ConnectionNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
            //allenBradleyConnectionNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
            tagNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message + " - " + ex.StackTrace);
            //}
        }
 public void Configure(EntityTypeBuilder <Domain.Entity.View.Joined.AllConnection> allConnectionConfiguration)
 {
     //RelationalEntityTypeBuilderExtensions.ToView((EntityTypeBuilder) allConnectionConfiguration, "AllConnectionView", KSociety.Base.Infra.Shared.Class.DatabaseContext.DefaultSchema);
     RelationalEntityTypeBuilderExtensions.ToView((EntityTypeBuilder)allConnectionConfiguration, "AllConnectionView");
     allConnectionConfiguration.HasNoKey();
 }
Exemple #26
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("ProductVersion", "2.2.1-servicing-10028");

            modelBuilder.Entity <Albums>(entity =>
            {
                entity.HasKey(e => e.AlbumId);

                RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)entity, "albums");

                entity.HasIndex(e => e.ArtistId)
                .HasName("IFK_AlbumArtistId");

                entity.Property(e => e.AlbumId).ValueGeneratedNever();

                entity.Property(e => e.Title)
                .IsRequired()
                .HasColumnType("nvarchar")
                .HasMaxLength(160);

                entity.HasOne(d => d.Artist)
                .WithMany(p => p.Albums)
                .HasForeignKey(d => d.ArtistId)
                .OnDelete(DeleteBehavior.ClientSetNull);
            });

            modelBuilder.Entity <Artists>(entity =>
            {
                entity.HasKey(e => e.ArtistId);

                RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)entity, "artists");

                entity.Property(e => e.ArtistId).ValueGeneratedNever();

                entity.Property(e => e.Name)
                .HasColumnType("nvarchar")
                .HasMaxLength(120);
            });

            modelBuilder.Entity <Customers>(entity =>
            {
                entity.HasKey(e => e.CustomerId);

                RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)entity, "customers");

                entity.HasIndex(e => e.SupportRepId)
                .HasName("IFK_CustomerSupportRepId");

                entity.Property(e => e.CustomerId).ValueGeneratedNever();

                entity.Property(e => e.Address)
                .HasColumnType("nvarchar")
                .HasMaxLength(70);

                entity.Property(e => e.City)
                .HasColumnType("nvarchar")
                .HasMaxLength(40);

                entity.Property(e => e.Company)
                .HasColumnType("nvarchar")
                .HasMaxLength(80);

                entity.Property(e => e.Country)
                .HasColumnType("nvarchar")
                .HasMaxLength(40);

                entity.Property(e => e.Email)
                .IsRequired()
                .HasColumnType("nvarchar")
                .HasMaxLength(60);

                entity.Property(e => e.Fax)
                .HasColumnType("nvarchar")
                .HasMaxLength(24);

                entity.Property(e => e.FirstName)
                .IsRequired()
                .HasColumnType("nvarchar")
                .HasMaxLength(40);

                entity.Property(e => e.LastName)
                .IsRequired()
                .HasColumnType("nvarchar")
                .HasMaxLength(20);

                entity.Property(e => e.Phone)
                .HasColumnType("nvarchar")
                .HasMaxLength(24);

                entity.Property(e => e.PostalCode)
                .HasColumnType("nvarchar")
                .HasMaxLength(10);

                entity.Property(e => e.State)
                .HasColumnType("nvarchar")
                .HasMaxLength(40);

                entity.HasOne(d => d.SupportRep)
                .WithMany(p => p.Customers)
                .HasForeignKey(d => d.SupportRepId);
            });

            modelBuilder.Entity <Employees>(entity =>
            {
                entity.HasKey(e => e.EmployeeId);

                RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)entity, "employees");

                entity.HasIndex(e => e.ReportsTo)
                .HasName("IFK_EmployeeReportsTo");

                entity.Property(e => e.EmployeeId).ValueGeneratedNever();

                entity.Property(e => e.Address)
                .HasColumnType("nvarchar")
                .HasMaxLength(70);

                entity.Property(e => e.City)
                .HasColumnType("nvarchar")
                .HasMaxLength(40);

                entity.Property(e => e.Country)
                .HasColumnType("nvarchar")
                .HasMaxLength(40);

                entity.Property(e => e.Email)
                .HasColumnType("nvarchar")
                .HasMaxLength(60);

                entity.Property(e => e.Fax)
                .HasColumnType("nvarchar")
                .HasMaxLength(24);

                entity.Property(e => e.FirstName)
                .IsRequired()
                .HasColumnType("nvarchar")
                .HasMaxLength(20);

                entity.Property(e => e.LastName)
                .IsRequired()
                .HasColumnType("nvarchar")
                .HasMaxLength(20);

                entity.Property(e => e.Phone)
                .HasColumnType("nvarchar")
                .HasMaxLength(24);

                entity.Property(e => e.PostalCode)
                .HasColumnType("nvarchar")
                .HasMaxLength(10);

                entity.Property(e => e.State)
                .HasColumnType("nvarchar")
                .HasMaxLength(40);

                entity.Property(e => e.Title)
                .HasColumnType("nvarchar")
                .HasMaxLength(30);

                entity.HasOne(d => d.ReportsToNavigation)
                .WithMany(p => p.InverseReportsToNavigation)
                .HasForeignKey(d => d.ReportsTo);
            });

            modelBuilder.Entity <Genres>(entity =>
            {
                entity.HasKey(e => e.GenreId);

                RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)entity, "genres");

                entity.Property(e => e.GenreId).ValueGeneratedNever();

                entity.Property(e => e.Name)
                .HasColumnType("nvarchar")
                .HasMaxLength(120);
            });

            modelBuilder.Entity <InvoiceItems>(entity =>
            {
                entity.HasKey(e => e.InvoiceLineId);

                RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)entity, "invoice_items");

                entity.HasIndex(e => e.InvoiceId)
                .HasName("IFK_InvoiceLineInvoiceId");

                entity.HasIndex(e => e.TrackId)
                .HasName("IFK_InvoiceLineTrackId");

                entity.Property(e => e.InvoiceLineId).ValueGeneratedNever();

                entity.Property(e => e.UnitPrice).HasColumnType("numeric(10,2)");

                entity.HasOne(d => d.Invoice)
                .WithMany(p => p.InvoiceItems)
                .HasForeignKey(d => d.InvoiceId)
                .OnDelete(DeleteBehavior.ClientSetNull);

                entity.HasOne(d => d.Track)
                .WithMany(p => p.InvoiceItems)
                .HasForeignKey(d => d.TrackId)
                .OnDelete(DeleteBehavior.ClientSetNull);
            });

            modelBuilder.Entity <Invoices>(entity =>
            {
                entity.HasKey(e => e.InvoiceId);

                entity.ToTable("invoices");

                entity.HasIndex(e => e.CustomerId)
                .HasName("IFK_InvoiceCustomerId");

                entity.Property(e => e.InvoiceId).ValueGeneratedNever();

                entity.Property(e => e.BillingAddress)
                .HasColumnType("nvarchar")
                .HasMaxLength(70);

                entity.Property(e => e.BillingCity)
                .HasColumnType("nvarchar")
                .HasMaxLength(40);

                entity.Property(e => e.BillingCountry)
                .HasColumnType("nvarchar")
                .HasMaxLength(40);

                entity.Property(e => e.BillingPostalCode)
                .HasColumnType("nvarchar")
                .HasMaxLength(10);

                entity.Property(e => e.BillingState)
                .HasColumnType("nvarchar")
                .HasMaxLength(40);

                entity.Property(e => e.Total).HasColumnType("numeric(10,2)");

                entity.HasOne(d => d.Customer)
                .WithMany(p => p.Invoices)
                .HasForeignKey(d => d.CustomerId)
                .OnDelete(DeleteBehavior.ClientSetNull);
            });

            modelBuilder.Entity <MediaTypes>(entity =>
            {
                entity.HasKey(e => e.MediaTypeId);

                entity.ToTable("media_types");

                entity.Property(e => e.MediaTypeId).ValueGeneratedNever();

                entity.Property(e => e.Name)
                .HasColumnType("nvarchar")
                .HasMaxLength(120);
            });

            modelBuilder.Entity <PlaylistTrack>(entity =>
            {
                entity.HasKey(e => new { e.PlaylistId, e.TrackId });

                entity.ToTable("playlist_track");

                entity.HasIndex(e => e.TrackId)
                .HasName("IFK_PlaylistTrackTrackId");

                entity.HasOne(d => d.Playlist)
                .WithMany(p => p.PlaylistTrack)
                .HasForeignKey(d => d.PlaylistId)
                .OnDelete(DeleteBehavior.ClientSetNull);

                entity.HasOne(d => d.Track)
                .WithMany(p => p.PlaylistTrack)
                .HasForeignKey(d => d.TrackId)
                .OnDelete(DeleteBehavior.ClientSetNull);
            });

            modelBuilder.Entity <Playlists>(entity =>
            {
                entity.HasKey(e => e.PlaylistId);

                entity.ToTable("playlists");

                entity.Property(e => e.PlaylistId).ValueGeneratedNever();

                entity.Property(e => e.Name)
                .HasColumnType("nvarchar")
                .HasMaxLength(120);
            });

            modelBuilder.Entity <Tracks>(entity =>
            {
                entity.HasKey(e => e.TrackId);

                RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)entity, "tracks");

                entity.HasIndex(e => e.AlbumId)
                .HasName("IFK_TrackAlbumId");

                entity.HasIndex(e => e.GenreId)
                .HasName("IFK_TrackGenreId");

                entity.HasIndex(e => e.MediaTypeId)
                .HasName("IFK_TrackMediaTypeId");

                entity.Property(e => e.TrackId).ValueGeneratedNever();

                entity.Property(e => e.Composer)
                .HasColumnType("nvarchar")
                .HasMaxLength(220);

                entity.Property(e => e.Name)
                .IsRequired()
                .HasColumnType("nvarchar")
                .HasMaxLength(200);

                entity.Property(e => e.UnitPrice).HasColumnType("numeric(10,2)");

                entity.HasOne(d => d.Album)
                .WithMany(p => p.Tracks)
                .HasForeignKey(d => d.AlbumId);

                entity.HasOne(d => d.Genre)
                .WithMany(p => p.Tracks)
                .HasForeignKey(d => d.GenreId);

                entity.HasOne(d => d.MediaType)
                .WithMany(p => p.Tracks)
                .HasForeignKey(d => d.MediaTypeId)
                .OnDelete(DeleteBehavior.ClientSetNull);
            });
        }
Exemple #27
0
        public void Configure(EntityTypeBuilder <Domain.Entity.Common.Tag> tagConfiguration)
        {
            //RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder) tagConfiguration, "Tag", KSociety.Base.Infra.Shared.Class.DatabaseContext.DefaultSchema);
            RelationalEntityTypeBuilderExtensions.ToTable((EntityTypeBuilder)tagConfiguration, "Tag");

            tagConfiguration.HasKey(k => k.Id);
            tagConfiguration.Property(p => p.Id).ValueGeneratedOnAdd().IsRequired();

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)tagConfiguration.HasOne(c => c.AutomationType)
                                                                    .WithMany(cc => cc.Tags)
                                                                    .HasForeignKey(fk => fk.AutomationTypeId), "ForeignKey_Tag_AutomationType")
            .IsRequired()
            .OnDelete(DeleteBehavior.Restrict);

            tagConfiguration.HasDiscriminator(d => d.AutomationTypeId)
            .HasValue <Domain.Entity.Common.Tag>(0)
            .HasValue <Domain.Entity.S7.S7Tag>(1)
            .HasValue <Domain.Entity.Logix.LogixTag>(2)
            .HasValue <Domain.Entity.Modbus.ModbusTag>(3)
            .HasValue <Domain.Entity.Tcp.TcpTag>(4);


            //tagConfiguration.HasOne(c => c.AutomationType).WithMany(cc => cc.StdTags)
            //    .HasForeignKey(fk => fk.AutomationTypeId).HasConstraintName("ForeignKey_Tag_AutomationType")
            //    .IsRequired();

            tagConfiguration.HasIndex(i => new { i.Name, i.AutomationTypeId }).IsUnique();
            tagConfiguration.Property(p => p.Name).HasMaxLength(50).IsRequired();

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)tagConfiguration.HasOne(c => c.Connection)
                                                                    .WithMany(cc => cc.Tags)
                                                                    .HasForeignKey(fk => fk.ConnectionId), "ForeignKey_Tag_ConnectionId")
            .IsRequired();

            tagConfiguration.Property(p => p.Enable).IsRequired();

            tagConfiguration.Property(p => p.MemoryAddress).HasMaxLength(50).IsRequired();

            tagConfiguration.Property(p => p.Invoke).IsRequired();

            //tagConfiguration.Property(p => p.InputOutput).IsRequired();
            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)tagConfiguration.HasOne(c => c.InOut).WithMany(cc => cc.Tags)
                                                                    .HasForeignKey(fk => fk.InputOutput), "ForeignKey_Tag_InOut")
            .IsRequired();

            //tagConfiguration.Property(p => p.AnalogDigitalSignal).IsRequired();
            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)tagConfiguration.HasOne(c => c.AnalogDigital).WithMany(cc => cc.Tags)
                                                                    .HasForeignKey(fk => fk.AnalogDigitalSignal), "ForeignKey_Tag_AnalogDigital")
            .IsRequired();

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)tagConfiguration.HasOne(c => c.TagGroup).WithMany(cc => cc.Tags)
                                                                    .HasForeignKey(fk => fk.TagGroupId), "ForeignKey_Tag_TagGroup")
            .IsRequired();

            tagConfiguration.Ignore(i => i.OldValue);

            tagConfiguration.Ignore(i => i.Value);

            tagConfiguration.Ignore(i => i.Timestamp);

            //tagConfiguration.Ignore(i => i.TagReadEvent);
            //tagConfiguration.Ignore(i => i.TagWriteEvent);

            //tagConfiguration
            //    .HasOne(s7T => s7T.S7Tag)
            //    .WithOne(t => t.StdTag)
            //    .HasForeignKey<Domain.Com.Entity.S7.S7Tag>(t => t.StdTagId)
            //    .HasConstraintName("ForeignKey_Tag_S7Tag")
            //    .IsRequired();

            //tagConfiguration
            //    .HasOne(logixT => logixT.LogixTag)
            //    .WithOne(t => t.StdTag)
            //    .HasForeignKey<Domain.Com.Entity.Logix.LogixTag>(t => t.StdTagId)
            //    .HasConstraintName("ForeignKey_Tag_LogixTag")
            //    .IsRequired();

            //var s7TagNavigation = tagConfiguration
            //    .Metadata.FindNavigation(nameof(Domain.Com.Entity.Common.Tag.S7Tags));

            //var allenBradleyTagNavigation = tagConfiguration
            //    .Metadata.FindNavigation(nameof(Domain.Com.Entity.Common.Tag.LogixTags));

            //s7TagNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
            //allenBradleyTagNavigation.SetPropertyAccessMode(PropertyAccessMode.Field);
        }