使用 Visual Studio 2022 创建 ASP.NET Core Web API
可以从 Visual Studio 2022 中选择 ASP.NET Core Web API 或 ASP.NET Core gRPC模板
安装依赖库,可以使用NuGet安装或使用DotNet CLI
1 | dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 6.0.33 |
在appsettings.json
中添加配置
1 | { |
准备Model
1 | using Microsoft.AspNetCore.Identity; |
Fluent API重定义数据库表名,字段
1 | using Sample.Identity.Model; |
新建DataContext
1 | using Microsoft.AspNetCore.Identity.EntityFrameworkCore; |
添加ViewModel
1 | using System.ComponentModel.DataAnnotations; |
添加Controller
1 | using Sample.Identity.ViewModels; |
修改Program中添加
1 | using Sample.Identity; |
执行数据迁移
1 | add-migration L0 |