using FateMaster.API.Models; using Microsoft.EntityFrameworkCore; namespace FateMaster.API.Data; public class ApplicationDbContext : DbContext { public ApplicationDbContext(DbContextOptions options) : base(options) { } public DbSet DivinationRecords { get; set; } public DbSet SystemConfigs { get; set; } public DbSet PriceConfigs { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); // 配置索引 modelBuilder.Entity() .HasIndex(d => d.Type); modelBuilder.Entity() .HasIndex(d => d.PaymentStatus); modelBuilder.Entity() .HasIndex(d => d.CreatedAt); modelBuilder.Entity() .HasIndex(s => s.ConfigKey) .IsUnique(); modelBuilder.Entity() .HasIndex(p => p.ServiceType); // 初始化数据 modelBuilder.Entity().HasData( new PriceConfig { Id = 1, ServiceType = "bazi", Price = 99, Currency = "CNY" }, new PriceConfig { Id = 2, ServiceType = "career", Price = 88, Currency = "CNY" }, new PriceConfig { Id = 3, ServiceType = "marriage", Price = 88, Currency = "CNY" }, new PriceConfig { Id = 4, ServiceType = "tarot", Price = 66, Currency = "CNY" }, new PriceConfig { Id = 5, ServiceType = "zodiac", Price = 29, Currency = "CNY" } ); } }