Добавил ограничение поля в БД

parent 7d58cb25
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Payment.WebApi.Models.DbModels;
namespace Payment.WebApi.Infrastructures.Databases.MapConfigurations;
public class UserBalanceDbMap : IEntityTypeConfiguration<UserBalance>
{
public void Configure(EntityTypeBuilder<UserBalance> builder)
{
builder.HasKey(opt => opt.Id);
builder.Property(opt => opt.Currency).HasMaxLength(8).IsRequired();
builder.Property(opt => opt.Amount).HasColumnType("NUMERIC(18,2)");
}
}
\ No newline at end of file
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Payment.WebApi.Models.DbModels;
namespace Payment.WebApi.Infrastructures.Databases.MapConfigurations;
public class UserDbMap : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder.HasKey(opt => opt.Id);
builder.Property(opt => opt.FirstName).HasColumnType("VARCHAR(256)").IsRequired();
builder.Property(opt => opt.LastName).HasColumnType("VARCHAR(256)");
builder.Property(opt => opt.MiddleName).HasColumnType("VARCHAR(256)");
builder.Property(opt => opt.Email).HasMaxLength(128).IsRequired();
builder.Property(opt => opt.Age).HasColumnType("SMALLINT");
}
}
\ No newline at end of file
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Payment.WebApi.Infrastructures.Databases.MapConfigurations;
using Payment.WebApi.Models.DbModels; using Payment.WebApi.Models.DbModels;
namespace Payment.WebApi.Infrastructures.Databases; namespace Payment.WebApi.Infrastructures.Databases;
...@@ -24,5 +25,8 @@ public class PaymentDbContext : DbContext ...@@ -24,5 +25,8 @@ public class PaymentDbContext : DbContext
modelBuilder.SeedUser(); modelBuilder.SeedUser();
modelBuilder.SeedSupplier(); modelBuilder.SeedSupplier();
modelBuilder.SeedUserBalance(); modelBuilder.SeedUserBalance();
modelBuilder.ApplyConfiguration(new UserDbMap());
modelBuilder.ApplyConfiguration(new UserBalanceDbMap());
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment