返回
EF报错System.Exception: You need to call SQLitePCL.raw.SetProvider().
2023-02-15 4938 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) Core 10新特性全面解析:提升开发效率的关键更新
Entity Framework(EF)DbContext SaveChanges()生命周期
EF Core 6(EF6)没有SqlQuery方法
.NET Entity Framework(EF)高性能分页
EF报错Win32Exception: 证书链是由不受信任的颁发机构颁发的。
EF Core在非MVC项目中需要手动释放吗?
Angular UT报错Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError
EF Core预热处理优化
相关帖子
PMC报错Scaffold-DbContext : 无法将“Scaffold-DbContext”项识别为 cmdlet、函数、脚本
Blazor 路由参数报错 No writer was cached for the property 'MyId' on type 'BlazorApp2.Pages.Index'.
Switch模拟器最新固件firmware密匙prod.keys 21.0.0固件、驱动+Switch游戏资源下载
微软Copilot将升至GPT-4 Turbo并提高字符上限
GBA模拟器 VisualBoyAdvance-M v2.2.3 中文绿色版 支持GBA/GB/GBC
有哪些方法推广新网站,增加搜索引擎收录
Zen Browser:开源 Firefox 分支带来的隐私体验与生产力提升
Cloudflare Workers 是什么?国内可以使用吗?全面解析边缘计算平台优势