https://github.com/densen2014/Blazor100/tree/Blazor-%E6%95%99%E7%A8%8B15-3/b15blazorIDS
appsettings.json
文件加入一行代码 "IdsSQliteConnection": "Data Source=ids.db;"
最终文件如下
{
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=aspnet-b15blazorIDS-f969184b-89a5-4ccf-beeb-911a756ae70a;Trusted_Connection=True;MultipleActiveResultSets=true",
"IdsSQliteConnection": "Data Source=ids.db;"
},
...
}
Program.cs
文件//EF SqlServer 配置
// Add services to the container.
//var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
//builder.Services.AddDbContext(options => options.UseSqlServer(connectionString));
//EF Sqlite 配置
builder.Services.AddDbContext(o => o.UseSqlite(builder.Configuration.GetConnectionString("IdsSQliteConnection")));
之前版本是基于localdb,如果不换脚本会出现An error occurred applying migrations, try applying them from the command line
错误
可选: 保留sqlserver的Migrations脚本, 使用 从项目中排除 菜单
打开命令行, VS菜单栏=>工具=>Nuget包管理器=>程序包管理器控制台(Packge Manager Console), 执行以下命令
cd b15blazorIDS
dotnet ef migrations add idsSqlite
dotnet ef database update
PM> cd b15blazorIDS
PM> dotnet ef migrations add idsSqlite
Build started...
Build succeeded.
Done. To undo this action, use 'ef migrations remove'
PM> dotnet ef database update
Build started...
Build succeeded.
info: Microsoft.EntityFrameworkCore.Database.Command[20101]
Executed DbCommand (7ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT COUNT(*) FROM "sqlite_master" WHERE "name" = '__EFMigrationsHistory' AND "type" = 'table';
...
Done.
PM>
https://localhost:7011/Identity/Account/Register
页面注册Password | Confirm Password | |
---|---|---|
[email protected] | 000000 | 000000 |
[email protected] | 000000 | 000000 |
https://github.com/densen2014/Blazor100/tree/Blazor-%E6%95%99%E7%A8%8B15-3/b15blazorIDS
https://github.com/densen2014/Blazor100
https://gitee.com/densen2014/Blazor100 (镜像/非最新版)—
FreeSql QQ群:4336577
BA & Blazor QQ群: 795206915
Maui Blazor 中文社区 QQ群:645660665
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名AlexChow,不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我联系 。
本文来自博客园,作者:周创琳 AlexChow,转载请注明原文链接.
今日头条 | 博客园 | 知乎 | Gitee | GitHub