36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
using Apimanager_backend.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System.Reflection;
|
|
|
|
namespace Apimanager_backend.Data
|
|
{
|
|
public class ApiContext:DbContext
|
|
{
|
|
//API表
|
|
public DbSet<Api> Apis { get; set; }
|
|
//用户表
|
|
public DbSet<User> Users { get; set; }
|
|
//API调用日志
|
|
public DbSet<ApiCallLog> CallLogs { get; set; }
|
|
//套餐表
|
|
public DbSet<Apipackage> Apipackages { get; set; }
|
|
//操作日志表
|
|
public DbSet<OperationLog> OperationLogs { get; set; }
|
|
//订单表
|
|
public DbSet<Order> Orders { get; set; }
|
|
//用户已订购套餐表
|
|
public DbSet<UserPackage> UserPackages { get; set; }
|
|
//用户角色表
|
|
public DbSet<UserRole> UserRoles { get; set; }
|
|
public ApiContext(DbContextOptions<ApiContext> options) : base(options) { }
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
modelBuilder.ApplyConfigurationsFromAssembly(typeof(ApiContext).Assembly);
|
|
// 配置全局查询筛选器
|
|
modelBuilder.Entity<User>().HasQueryFilter(u => !u.IsDelete);
|
|
modelBuilder.Entity<Api>().HasQueryFilter(a => !a.IsDelete);
|
|
}
|
|
|
|
}
|
|
}
|