fengling-risk-control/Fengling.RiskControl.Infrastructure/RiskControlDbContext.cs

65 lines
2.5 KiB
C#

using Microsoft.EntityFrameworkCore;
using NetCorePal.Extensions.Domain;
using Fengling.RiskControl.Domain.Aggregates.RiskRules;
using Fengling.RiskControl.Domain.Aggregates.RiskScores;
using Fengling.RiskControl.Domain.Aggregates.RiskAlerts;
using Fengling.RiskControl.Domain.Aggregates.LotteryActivities;
namespace Fengling.RiskControl.Infrastructure;
public class RiskControlDbContext : DbContext
{
public DbSet<RiskRule> RiskRules => Set<RiskRule>();
public DbSet<RiskScore> RiskScores => Set<RiskScore>();
public DbSet<RiskAlert> RiskAlerts => Set<RiskAlert>();
public DbSet<LotteryActivity> LotteryActivities => Set<LotteryActivity>();
private RiskControlDbContext() { }
public RiskControlDbContext(DbContextOptions<RiskControlDbContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<RiskRule>(builder =>
{
builder.ToTable("rc_risk_rules");
builder.HasKey(r => r.Id);
builder.Property(r => r.Name).HasMaxLength(100).IsRequired();
builder.Property(r => r.Description).HasMaxLength(500);
builder.Property(r => r.ConfigJson).HasColumnName("config_json");
builder.Property(r => r.IsActive).HasDefaultValue(true);
});
modelBuilder.Entity<RiskScore>(builder =>
{
builder.ToTable("rc_risk_scores");
builder.HasKey(s => s.Id);
builder.Property(s => s.MemberId).IsRequired();
builder.Property(s => s.EntityType).HasMaxLength(50).IsRequired();
builder.Property(s => s.EntityId).HasMaxLength(100).IsRequired();
});
modelBuilder.Entity<RiskAlert>(builder =>
{
builder.ToTable("rc_risk_alerts");
builder.HasKey(a => a.Id);
builder.Property(a => a.MemberId).IsRequired();
builder.Property(a => a.AlertType).HasMaxLength(50).IsRequired();
builder.Property(a => a.Description).HasMaxLength(500);
});
modelBuilder.Entity<LotteryActivity>(builder =>
{
builder.ToTable("rc_lottery_activities");
builder.HasKey(l => l.Id);
builder.Property(l => l.MemberId).IsRequired();
builder.Property(l => l.ActivityType).HasMaxLength(50).IsRequired();
builder.Property(l => l.IpAddress).HasMaxLength(50);
builder.Property(l => l.DeviceId).HasMaxLength(100);
});
}
}