feat: 将数据库模型和迁移集中到 EFCore 项目
- 将 AppDataContext、实体模型、Migrations 从 Avalonia-Services 移动到 Avalonia-EFCore - 更新 API、PC、Services 中的数据库上下文和实体引用命名空间 - 在实体上显式绑定表名、字段名和数据库注释 - 更新 InitialCreate、Designer、Snapshot,使用新的表名、字段名和注释 - 新增 AppDataContextFactory,支持 dotnet ef 设计时创建 DbContext - 新增本地 dotnet-ef 工具清单 - 新增一键生成迁移脚本 add-migration.ps1 / .cmd / .bat - 启动时自动检测并执行未应用迁移 - 从 appsettings.json 读取数据库配置
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Avalonia_EFCore.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 用户实体 —— 演示数据库 CRUD 操作。
|
||||
/// </summary>
|
||||
[Comment("用户实体,演示数据库 CRUD 操作")]
|
||||
[Table("user")]
|
||||
public class UserEntity
|
||||
{
|
||||
[Key]
|
||||
[Comment("用户主键")]
|
||||
[Column("id")]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Comment("用户名称")]
|
||||
[Column("name")]
|
||||
[MaxLength(100)]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[Comment("用户邮箱")]
|
||||
[Column("email")]
|
||||
[MaxLength(200)]
|
||||
public string? Email { get; set; }
|
||||
|
||||
[Comment("电话号码")]
|
||||
[Column("phone-number")]
|
||||
[MaxLength(50)]
|
||||
public string? PhoneNumber { get; set; }
|
||||
|
||||
[Comment("创建时间")]
|
||||
[Column("created-at")]
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
[Comment("更新时间")]
|
||||
[Column("updated-at")]
|
||||
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Avalonia_EFCore.Models
|
||||
{
|
||||
public class WeatherForecast
|
||||
{
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
|
||||
public string? Summary { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace Avalonia_EFCore.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// 天气预报数据实体。
|
||||
/// </summary>
|
||||
[Comment("天气预报数据实体")]
|
||||
[Table("weather-forecast")]
|
||||
public class WeatherForecastEntity
|
||||
{
|
||||
[Key]
|
||||
[Comment("天气预报主键")]
|
||||
[Column("id")]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[Comment("预报日期")]
|
||||
[Column("date")]
|
||||
public DateOnly Date { get; set; }
|
||||
|
||||
[Comment("摄氏温度")]
|
||||
[Column("temperature-c")]
|
||||
public int TemperatureC { get; set; }
|
||||
|
||||
[Comment("天气摘要")]
|
||||
[Column("summary")]
|
||||
[MaxLength(200)]
|
||||
public string? Summary { get; set; }
|
||||
|
||||
[Comment("创建时间")]
|
||||
[Column("created-at")]
|
||||
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
|
||||
|
||||
[Comment("更新时间")]
|
||||
[Column("updated-at")]
|
||||
public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user