Files
fatemaster/backend/FateMaster.API/Data/ApplicationDbContext.cs
jiangdong d81cf186b0 init
2025-10-03 11:24:11 +08:00

48 lines
1.6 KiB
C#

using FateMaster.API.Models;
using Microsoft.EntityFrameworkCore;
namespace FateMaster.API.Data;
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<DivinationRecord> DivinationRecords { get; set; }
public DbSet<SystemConfig> SystemConfigs { get; set; }
public DbSet<PriceConfig> PriceConfigs { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// 配置索引
modelBuilder.Entity<DivinationRecord>()
.HasIndex(d => d.Type);
modelBuilder.Entity<DivinationRecord>()
.HasIndex(d => d.PaymentStatus);
modelBuilder.Entity<DivinationRecord>()
.HasIndex(d => d.CreatedAt);
modelBuilder.Entity<SystemConfig>()
.HasIndex(s => s.ConfigKey)
.IsUnique();
modelBuilder.Entity<PriceConfig>()
.HasIndex(p => p.ServiceType);
// 初始化数据
modelBuilder.Entity<PriceConfig>().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" }
);
}
}