返回
EF报错System.Exception: You need to call SQLitePCL.raw.SetProvider().
2023-02-15 4994 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包就可以了。

网友点评
提交
相关阅读
Entity Framework(EF)DbContext SaveChanges()生命周期
.NET C# EntityFrameworkCore(EF)连接PostgreSQL数据库
EF Core 6(EF6)没有SqlQuery方法
.NET Entity Framework(EF)高性能分页
EntityFramework(EF) 控制并发和事务防止超卖
Angular UT报错Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError
EF Core在非MVC项目中需要手动释放吗?
EntityFramework(EF) SQLite常见问题和解决方案
相关帖子
PMC报错Scaffold-DbContext : 无法将“Scaffold-DbContext”项识别为 cmdlet、函数、脚本
Blazor 路由参数报错 No writer was cached for the property 'MyId' on type 'BlazorApp2.Pages.Index'.
网易UU加速器 vs 雷霆加速器:全面测评 + 真实对比(2025年版)
2025 年最佳 AI 股票量化交易工具推荐 | 智能模型助力专业交易
把炒币赚的钱提现,银行会追查吗?
植物大战僵尸杂交重制版最新版 益智悠闲小游戏 电脑|安卓手机版 v0.4
GLaDOS机场评测:高速稳定的V2Ray/Trojan加速器服务
wallless机场怎么样?wallless官网打不开,不能用了?wallless机场跑路了?推荐替代 – DOVE加速器