using Avalonia_EFCore.Database; using Avalonia_Services.Models; using Microsoft.EntityFrameworkCore; namespace Avalonia_Services.Database { /// /// 应用数据库上下文 —— 继承自 Avalonia-EFCore 的 AppDbContext。 /// 所有业务实体在此注册 DbSet。 /// 这是 Avalonia-API 和 Avalonia-PC 共用的具体数据上下文。 /// public class AppDataContext(DatabaseConfiguration dbConfig) : AppDbContext(dbConfig) { /// 天气预报数据 public DbSet WeatherForecasts => Set(); /// 用户数据 public DbSet Users => Set(); protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity(entity => { entity.HasKey(e => e.Id); entity.Property(e => e.Summary).HasMaxLength(200); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.Id); entity.Property(e => e.Email).HasMaxLength(200); }); } } }