重构项目结构,引入 Avalonia-Common、Avalonia-EFCore、Avalonia-Services,实现 API 与桌面端统一端点注册、过滤器、鉴权和标准响应格式。支持多数据库自动迁移与配置,集成 Serilog 日志系统。移除旧路由与控制器,提升接口一致性与可维护性。
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using Avalonia_EFCore.Database;
|
|
using Avalonia_Services.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Avalonia_Services.Database
|
|
{
|
|
/// <summary>
|
|
/// 应用数据库上下文 —— 继承自 Avalonia-EFCore 的 AppDbContext。
|
|
/// 所有业务实体在此注册 DbSet。
|
|
/// 这是 Avalonia-API 和 Avalonia-PC 共用的具体数据上下文。
|
|
/// </summary>
|
|
public class AppDataContext(DatabaseConfiguration dbConfig) : AppDbContext(dbConfig)
|
|
{
|
|
/// <summary>天气预报数据</summary>
|
|
public DbSet<WeatherForecastEntity> WeatherForecasts => Set<WeatherForecastEntity>();
|
|
|
|
/// <summary>用户数据</summary>
|
|
public DbSet<UserEntity> Users => Set<UserEntity>();
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
modelBuilder.Entity<WeatherForecastEntity>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.Property(e => e.Summary).HasMaxLength(200);
|
|
});
|
|
|
|
modelBuilder.Entity<UserEntity>(entity =>
|
|
{
|
|
entity.HasKey(e => e.Id);
|
|
entity.Property(e => e.Email).HasMaxLength(200);
|
|
});
|
|
}
|
|
}
|
|
}
|