Exemple #1
0
        public override void Configure(EntityTypeBuilder <Product> builder)
        {
            builder.HasKey(p => p.Id);

            builder.HasIndex(p => p.Name);
            builder.HasIndex(p => p.Price);

            builder.Property(os => os.CreateDate).HasDefaultValueSql("getutcdate()").ValueGeneratedOnAdd();
            builder.Property(os => os.UpdateDate).HasDefaultValueSql("getutcdate()").ValueGeneratedOnAddOrUpdate();

            builder.Property(p => p.CategoryId).HasColumnName(string.Format(
                                                                  Consts.StrictForeignKeyName, DefaultTableConvension.GetColumnPrefix(nameof(Product)), DefaultTableConvension.GetColumnPrefix(nameof(Category))));

            builder.Property(p => p.CreateUserId).HasColumnName($"{DefaultTableConvension.GetColumnPrefix(nameof(Product))}_{nameof(OrderStatus.CreateUserId)}");
            builder.Property(p => p.UpdateUserId).HasColumnName($"{DefaultTableConvension.GetColumnPrefix(nameof(Product))}_{nameof(OrderStatus.UpdateUserId)}");

            builder.HasOne(p => p.Category)
            .WithMany(c => c.Products)
            .HasForeignKey(p => p.CategoryId)
            .OnDelete(DeleteBehavior.Restrict);

            builder.HasOne(p => p.CreateUser)
            .WithMany(u => u.CreatedProducts)
            .HasForeignKey(p => p.CreateUserId)
            .OnDelete(DeleteBehavior.Restrict);

            builder.HasOne(p => p.UpdateUser)
            .WithMany(u => u.UpdatedProducts)
            .HasForeignKey(p => p.UpdateUserId)
            .OnDelete(DeleteBehavior.Restrict);
        }
        public override void Configure(EntityTypeBuilder <OrderStatus> builder)
        {
            builder.HasKey(os => os.Id);

            builder.HasIndex(os => os.Name);

            builder.Property(os => os.CreateDate).HasDefaultValueSql("getutcdate()").ValueGeneratedOnAdd();
            builder.Property(os => os.UpdateDate).HasDefaultValueSql("getutcdate()").ValueGeneratedOnAddOrUpdate();

            builder.Property(os => os.CreateUserId).HasColumnName($"{DefaultTableConvension.GetColumnPrefix(nameof(OrderStatus))}_{nameof(OrderStatus.CreateUserId)}");
            builder.Property(os => os.UpdateUserId).HasColumnName($"{DefaultTableConvension.GetColumnPrefix(nameof(OrderStatus))}_{nameof(OrderStatus.UpdateUserId)}");

            builder.HasOne(os => os.CreateUser)
            .WithMany(u => u.CreatedOrderStatuses)
            .HasForeignKey(os => os.CreateUserId)
            .OnDelete(DeleteBehavior.Restrict);

            builder.HasOne(os => os.UpdateUser)
            .WithMany(u => u.UpdatedOrderStatuses)
            .HasForeignKey(os => os.UpdateUserId)
            .OnDelete(DeleteBehavior.Restrict);
        }
Exemple #3
0
        private void SetNames(ModelBuilder modelBuilder)
        {
            foreach (var entityType in modelBuilder.Model.GetEntityTypes().Reverse())
            {
                foreach (var property in entityType.GetProperties())
                {
                    if (!property.IsForeignKey())
                    {
                        property.SetColumnName(
                            string.Format("{0}_{1}",
                                          DefaultTableConvension.GetColumnPrefix(entityType.GetTableName()),
                                          property.GetColumnName())
                            );
                    }
                }

                if (!entityType.IsOwned())
                {
                    entityType.SetTableName($"tbl{entityType.GetTableName()}");
                }
            }
        }
Exemple #4
0
        public override void Configure(EntityTypeBuilder <AuditLog> builder)
        {
            builder.HasKey(al => al.Id);

            builder.HasIndex(al => al.TableName);
            builder.HasIndex(al => al.Action);

            builder.Property(al => al.CreateDate).HasComputedColumnSql("getutcdate()").ValueGeneratedOnAdd();
            builder.Property(al => al.UpdateDate).HasComputedColumnSql("getutcdate()").ValueGeneratedOnUpdate();

            builder.Property(al => al.CreateUserId).HasColumnName($"{DefaultTableConvension.GetColumnPrefix(nameof(AuditLog))}_{nameof(OrderStatus.CreateUserId)}");
            builder.Property(al => al.UpdateUserId).HasColumnName($"{DefaultTableConvension.GetColumnPrefix(nameof(AuditLog))}_{nameof(OrderStatus.UpdateUserId)}");

            builder.HasOne(al => al.CreateUser)
            .WithMany(u => u.CreatedAuditLogs)
            .HasForeignKey(al => al.CreateUserId)
            .OnDelete(DeleteBehavior.Restrict);

            builder.HasOne(al => al.UpdateUser)
            .WithMany(u => u.UpdatedAuditLogs)
            .HasForeignKey(al => al.UpdateUserId)
            .OnDelete(DeleteBehavior.Restrict);
        }
Exemple #5
0
        public override void Configure(EntityTypeBuilder <AuditLogDetail> builder)
        {
            builder.HasKey(ald => ald.Id);

            builder.HasIndex(ald => ald.ValueFrom);
            builder.HasIndex(ald => ald.ValueTo);
            builder.HasIndex(ald => ald.FieldName);

            builder.Property(ald => ald.CreateDate).HasComputedColumnSql("getutcdate()").ValueGeneratedOnAdd();
            builder.Property(ald => ald.UpdateDate).HasComputedColumnSql("getutcdate()").ValueGeneratedOnUpdate();

            builder.Property(o => o.AuditLogId).HasColumnName(string.Format(
                                                                  Consts.StrictForeignKeyName, DefaultTableConvension.GetColumnPrefix(nameof(AuditLogDetail)), DefaultTableConvension.GetColumnPrefix(nameof(AuditLog))));

            builder.HasOne(ald => ald.AuditLog)
            .WithMany(al => al.AuditLogDetails)
            .HasForeignKey(ald => ald.AuditLogId)
            .OnDelete(DeleteBehavior.Cascade);
        }
        public override void Configure(EntityTypeBuilder <Order> builder)
        {
            builder.HasKey(o => o.Id);

            builder.HasIndex(o => o.Price);
            builder.HasIndex(o => o.Currency);

            builder.Property(o => o.CreateDate).HasDefaultValueSql("getutcdate()").ValueGeneratedOnAdd();
            builder.Property(o => o.UpdateDate).HasDefaultValueSql("getutcdate()").ValueGeneratedOnAddOrUpdate();

            builder.Property(o => o.CustomerId).HasColumnName(string.Format(
                                                                  Consts.StrictForeignKeyName, DefaultTableConvension.GetColumnPrefix(nameof(Order)), DefaultTableConvension.GetColumnPrefix(nameof(Customer))));

            builder.Property(o => o.OrderStatusId).HasColumnName(string.Format(
                                                                     Consts.StrictForeignKeyName, DefaultTableConvension.GetColumnPrefix(nameof(Order)), DefaultTableConvension.GetColumnPrefix(nameof(OrderStatus))));

            builder.Property(o => o.DeliveryDetailId).HasColumnName(string.Format(
                                                                        Consts.StrictForeignKeyName, DefaultTableConvension.GetColumnPrefix(nameof(Order)), DefaultTableConvension.GetColumnPrefix(nameof(DeliveryDetail))));

            builder.HasOne(o => o.Customer)
            .WithMany(c => c.Orders)
            .HasForeignKey(o => o.CustomerId)
            .OnDelete(DeleteBehavior.Restrict);

            builder.HasOne(o => o.OrderStatus)
            .WithMany(o => o.Orders)
            .HasForeignKey(o => o.OrderStatusId)
            .OnDelete(DeleteBehavior.Restrict);

            builder.HasOne(o => o.DeliveryDetail)
            .WithMany(o => o.Orders)
            .HasForeignKey(o => o.DeliveryDetailId)
            .OnDelete(DeleteBehavior.Restrict);
        }
        public override void Configure(EntityTypeBuilder <Invoice> builder)
        {
            builder.HasKey(i => i.Id);

            builder.HasIndex(i => i.PaymentId);
            builder.HasIndex(i => i.Price);
            builder.HasIndex(i => i.NameOnCard);
            builder.HasIndex(i => i.LastForDigit);

            builder.Property(i => i.CreateDate).HasDefaultValueSql("getutcdate()").ValueGeneratedOnAdd();
            builder.Property(i => i.UpdateDate).HasDefaultValueSql("getutcdate()").ValueGeneratedOnAddOrUpdate();

            builder.Property(i => i.OrderId).HasColumnName(string.Format(
                                                               Consts.StrictForeignKeyName, DefaultTableConvension.GetColumnPrefix(nameof(Invoice)), DefaultTableConvension.GetColumnPrefix(nameof(Order))));

            builder.HasOne(i => i.Order)
            .WithMany(u => u.Invoices)
            .HasForeignKey(i => i.OrderId)
            .OnDelete(DeleteBehavior.Cascade);
        }
        public override void Configure(EntityTypeBuilder <OrderItem> builder)
        {
            builder.HasKey(oi => oi.Id);

            builder.HasIndex(oi => oi.Quantity);

            builder.Property(oi => oi.CreateDate).HasDefaultValueSql("getutcdate()").ValueGeneratedOnAdd();
            builder.Property(oi => oi.UpdateDate).HasDefaultValueSql("getutcdate()").ValueGeneratedOnAddOrUpdate();

            builder.Property(o => o.OrderId).HasColumnName(string.Format(
                                                               Consts.StrictForeignKeyName, DefaultTableConvension.GetColumnPrefix(nameof(OrderItem)), DefaultTableConvension.GetColumnPrefix(nameof(Order))));

            builder.Property(o => o.ProductId).HasColumnName(string.Format(
                                                                 Consts.StrictForeignKeyName, DefaultTableConvension.GetColumnPrefix(nameof(OrderItem)), DefaultTableConvension.GetColumnPrefix(nameof(Product))));

            builder.HasOne(oi => oi.Order)
            .WithMany(o => o.OrderItems)
            .HasForeignKey(oi => oi.OrderId)
            .OnDelete(DeleteBehavior.Restrict);

            builder.HasOne(oi => oi.Product)
            .WithMany(p => p.OrderItems)
            .HasForeignKey(oi => oi.ProductId)
            .OnDelete(DeleteBehavior.Restrict);
        }