https://gitee
.com/densen2014/Blazor100/tree/Blazor-教程15-3/b15blazorIDS
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
最终文件如下
{ "ConnectionStrings": { "DefaultConnection": "Server=(localdb)\mssqllocaldb;Database=aspnet-b15blazorIDS-f969184b-89a5-4ccf-beeb-911a756ae70a;Trusted_Connection=True;MultipleActiveResultSets=true", "IdsSQliteConnection": "Data Source=ids.db;" }, ...}
//EF SqlServer 配置// Add services to the container.//var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");//builder.Services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(connectionString));//EF Sqlite 配置builder.Services.AddDbContext<ApplicationDbContext>(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 b15blazorIDSdotnet ef migrations add idsSqlitedotnet ef database update
PM> cd b15blazorIDSPM> dotnet ef migrations add idsSqliteBuild started...Build succeeded.Done. To undo this action, use 'ef migrations remove'PM> dotnet ef database updateBuild 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>
Password | Confirm Password | |
test@app.com | 000000 | 000000 |
user@app.com | 000000 | 000000 |
https://gitee.com/densen2014/Blazor100/tree/Blazor-教程15-3/b15blazorIDS
https://gitee.com/densen2014/Blazor100 (镜像/非最新版)
FreeSql
BA & Blazor
本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。欢迎转载、使用、重新发布,但务必保留文章署名AlexChow ,不得用于商业目的,基于本文修改后的作品务必以相同的许可发布。如有任何疑问,请与我联系 。
本文来自博客园,作者:周创琳 AlexChow,转载请注明原文链接:
https://www.cnblogs.com/densen2014/p/17083934.html
今日头条 | 博客园 | 知乎 | Gitee | GitHub