Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public void Configure(EntityTypeBuilder <Domain.Entity.S7.S7Connection> connectionConfiguration)
        {
            //connectionConfiguration.HasBaseType<Domain.Com.Entity.Common.Connection>();
            //connectionConfiguration.ToTable("S7Connection", ComContext.DefaultSchema);

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

            //connectionConfiguration.HasOne(c => c.StdConnection).WithMany(cc => cc.S7Connections)
            //    .HasForeignKey(fk => fk.StdConnectionId).HasConstraintName("ForeignKey_S7Connection_StdConnectionId")
            //    .IsRequired();

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

            //connectionConfiguration.Property(p => p.Ip).HasMaxLength(15).IsRequired();
            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)connectionConfiguration.HasOne(p => p.CpuType).WithMany(pp => pp.S7Connections)
                                                                    .HasForeignKey(fk => fk.CpuTypeId), "ForeignKey_S7Connection_S7CpuType");
            //.IsRequired();

            //connectionConfiguration.Property(p => p.CpuType).HasDefaultValue(0);


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

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

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)connectionConfiguration.HasOne(c => c.ConnectionType).WithMany(cc => cc.Connections)
                                                                    .HasForeignKey(fk => fk.ConnectionTypeId), "ForeignKey_S7Connection_S7ConnectionType");

            //connectionConfiguration.Property(p => p.ConnectionType).HasDefaultValue(1);
            //.IsRequired();

            //connectionConfiguration.Ignore(i => i.ConnectionId);
            //connectionConfiguration.Ignore(i => i.AutomationTypeId);
            //connectionConfiguration.Ignore(i => i.AutomationType);
            //connectionConfiguration.Ignore(i => i.Name);
            //connectionConfiguration.Ignore(i => i.Ip);
            //connectionConfiguration.Ignore(i => i.Enable);
            //connectionConfiguration.Ignore(i => i.WriteEnable);
            ////connectionConfiguration.Ignore(i => i.S7Connection);
            ////connectionConfiguration.Ignore(i => i.LogixConnection);
            //connectionConfiguration.Ignore(i => i.Tags);


            connectionConfiguration.Ignore(i => i.ClientRead);
            connectionConfiguration.Ignore(i => i.ClientWrite);


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

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

            //connectionConfiguration.Property(p => p.WriteEnable).IsRequired();
            //var navigation1 = areaConfiguration.Metadata.FindNavigation(nameof(Domain.Db.Entity.S7.Area.S7Tags));
            //var navigation2 = areaConfiguration.Metadata.FindNavigation(nameof(Domain.Db.Entity.S7.Area.S7BlockAreas));

            //navigation1.SetPropertyAccessMode(PropertyAccessMode.Field);
            //navigation2.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
        public TrackConfiguration(EntityTypeBuilder <Track> entity)
        {
            entity.HasIndex(e => e.AlbumId)
            .HasName("IFK_Album_Track");

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

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

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

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

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

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

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)entity.HasOne(d => d.Genre)
                                                                    .WithMany(p => p.Tracks)
                                                                    .HasForeignKey(d => d.GenreId), "FK__Track__GenreId__2A4B4B5E");

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)entity.HasOne(d => d.MediaType)
                                                                    .WithMany(p => p.Tracks)
                                                                    .HasForeignKey(d => d.MediaTypeId)
                                                                    .OnDelete(DeleteBehavior.Restrict), "FK__Track__MediaType__29572725");
        }
Exemplo n.º 4
0
        public void Configure(EntityTypeBuilder <Domain.Entity.S7.S7Tag> tagConfiguration)
        {
            //tagConfiguration.ToTable("S7Tag", ComContext.DefaultSchema);

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

            //tagConfiguration.HasOne(c => c.StdTag).WithMany(cc => cc.S7Tags)
            //    .HasForeignKey(fk => fk.StdTagId).HasConstraintName("ForeignKey_S7Tag_StdTag")
            //    .IsRequired();

            tagConfiguration.Property(p => p.DataBlock); //.IsRequired();

            tagConfiguration.Property(p => p.Offset);    //.IsRequired();

            //tagConfiguration.Property(p => p.BitOfByte).IsRequired();
            //tagConfiguration.HasOne(c => c.BitOfByte).WithMany(cc => cc.)
            //    .HasForeignKey(fk => fk.ConnectionTypeId).HasConstraintName("ForeignKey_S7Connection_S7ConnectionType")
            //    .IsRequired();

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

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

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

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

            //tagConfiguration.Property(p => p.InputOutput).IsRequired();

            //tagConfiguration.Property(p => p.AnalogDigitalSignal).IsRequired();

            //tagConfiguration.Property(p => p.ConnectionId).IsRequired();

            //tagConfiguration.Property(p => p.WordLenId).IsRequired();

            //tagConfiguration.Property(p => p.AreaId).IsRequired();

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)tagConfiguration.HasOne(c => c.Bit).WithMany(cc => cc.S7Tags)
                                                                    .HasForeignKey(fk => fk.BitOfByte), "ForeignKey_S7Tag_Bit");

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)tagConfiguration.HasOne(c => c.Area).WithMany(cc => cc.S7Tags)
                                                                    .HasForeignKey(fk => fk.AreaId), "ForeignKey_S7Tag_Area");
            //.IsRequired();

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)tagConfiguration.HasOne(c => c.WordLen).WithMany(cc => cc.S7Tags)
                                                                    .HasForeignKey(fk => fk.WordLenId), "ForeignKey_S7Tag_WordLen");
            //.IsRequired();
            tagConfiguration.Property(p => p.StringLength);

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

            //var navigation1 = areaConfiguration.Metadata.FindNavigation(nameof(Domain.Db.Entity.S7.Area.S7Tags));
            //var navigation2 = areaConfiguration.Metadata.FindNavigation(nameof(Domain.Db.Entity.S7.Area.S7BlockAreas));

            //navigation1.SetPropertyAccessMode(PropertyAccessMode.Field);
            //navigation2.SetPropertyAccessMode(PropertyAccessMode.Field);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasAnnotation("Relational:Collation", "Lithuanian_Lithuania.1252");

            modelBuilder.Entity <Manufacturer>(entity =>
            {
                entity.ToTable("Manufacturer", "Factory");

                entity.Property(e => e.Country)
                .IsRequired()
                .HasMaxLength(50);

                entity.Property(e => e.Name)
                .IsRequired()
                .HasMaxLength(50);

                entity.Property(e => e.FoundedAt)
                .HasColumnType("date");
            });

            modelBuilder.Entity <Product>(entity =>
            {
                entity.ToTable("Product", "Factory");

                entity.Property(e => e.Name)
                .IsRequired()
                .HasMaxLength(50);

                RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)
                                                                        entity.HasOne(d => d.Manufacturer)
                                                                        .WithMany(p => p.Products)
                                                                        .HasForeignKey(d => d.ManufacturerId), "FK_Product_Manufacturer");
            });

            modelBuilder.Entity <ProductPriceHistory>(entity =>
            {
                entity.ToTable("ProductPriceHistory", "Factory");

                entity.Property(e => e.Price)
                .HasColumnType("money");

                entity.Property(e => e.DateOfPrice)
                .HasColumnType("date");

                RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)
                                                                        entity.HasOne(d => d.Product)
                                                                        .WithMany(p => p.PriceHistory)
                                                                        .HasForeignKey(d => d.ProductId), "FK_ProductPriceHistory_Product");
            });

            OnModelCreatingPartial(modelBuilder);
        }
        public InvoiceLineConfiguration(EntityTypeBuilder <InvoiceLine> entity)
        {
            entity.HasIndex(e => e.InvoiceId)
            .HasName("IFK_Invoice_InvoiceLine");

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

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

            entity.HasOne(d => d.Invoice)
            .WithMany(p => p.InvoiceLines)
            .HasForeignKey(d => d.InvoiceId)
            .OnDelete(DeleteBehavior.Restrict)
            .HasConstraintName("FK__InvoiceLi__Invoi__2F10007B");

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)entity.HasOne(d => d.Track)
                                                                    .WithMany(p => p.InvoiceLines)
                                                                    .HasForeignKey(d => d.TrackId)
                                                                    .OnDelete(DeleteBehavior.Restrict), "FK__InvoiceLi__Track__2E1BDC42");
        }
        public PlaylistTrackConfiguration(EntityTypeBuilder <PlaylistTrack> entity)
        {
            entity.HasKey(e => new { e.PlaylistId, e.TrackId })
            .HasName("PK__Playlist__A4A6282E25869641");

            entity.HasIndex(e => e.PlaylistId)
            .HasName("IPK_PlaylistTrack");

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

            entity.HasOne(d => d.Playlist)
            .WithMany(p => p.PlaylistTracks)
            .HasForeignKey(d => d.PlaylistId)
            .OnDelete(DeleteBehavior.Restrict)
            .HasConstraintName("FK__PlaylistT__Playl__30F848ED");

            RelationalForeignKeyBuilderExtensions.HasConstraintName((ReferenceCollectionBuilder)entity.HasOne(d => d.Track)
                                                                    .WithMany(p => p.PlaylistTracks)
                                                                    .HasForeignKey(d => d.TrackId)
                                                                    .OnDelete(DeleteBehavior.Restrict), "FK__PlaylistT__Track__300424B4");
        }
Exemplo n.º 8
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);
            //}
        }
Exemplo n.º 9
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);
        }