返回
EF报错System.Exception: You need to call SQLitePCL.raw.SetProvider().
2023-02-15 4254 0
使用EntityFrameworkCore.Sqlite时报错了,System.Exception: 'You need to call SQLitePCL.raw.SetProvider(). If you are using a bundle package, this is done by calling SQLitePCL.Batteries.Init().'。
var scopeFactory = app.Services.GetRequiredService<IServiceScopeFactory>();
using (var scope = scopeFactory.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<ArticleContext>();
if (db.Database.EnsureCreated())
{
SeedData.Initialize(db);
}
}在执行到db.Database.EnsureCreated()是发生了异常:

检查了Nuget引用,发现项目安装了
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Sqlite.Core
这两个包。看上去不是代码的问题。
找到了解决方法是再安装Microsoft.EntityFrameworkCore.Sqlite包就可以了。

网友点评
提交
相关阅读
ASP.NET 使用Entity Framework (EF) 创建迁移修改SQLite数据库表结构
.NET EF连接MySQL数据库
Entity Framework Core反向工程DB First基于数据库生成DbContext和实体类
快手 CodeFlicker:与传统及主流 AI 集成开发环境(IDE)的差异化解析
Angular UT报错Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError
.NET C# EntityFrameworkCore(EF)连接PostgreSQL数据库
.NET8 AOT报错:System.IO.FileNotFoundException: Could not find file 'Microsoft.AspNetCore'
EF Core预热处理优化
相关帖子
PMC报错Scaffold-DbContext : 无法将“Scaffold-DbContext”项识别为 cmdlet、函数、脚本
EFCloud机场不能用了?EFCloud机场跑路了吗?推荐替代 – DOVE加速器
乌龟服更新报错 Couldn't patch Turtle Wow. See tw_update.log for details.
EFCloud 机场现状解析:到底好不好用?跑路了吗?
Blazor 路由参数报错 No writer was cached for the property 'MyId' on type 'BlazorApp2.Pages.Index'.
EFcloud 连不上了,是跑路了吗?
EFcloud机场不能用了?EFcloud机场跑路了?推荐完美替代 – DOVE加速器 评测
CentOS Linux报错[10498]: Failed at step EXEC spawning /root/xxx: Exec format error