Asp.net
DbContextOptionsBuilder 不包含“UseSqlite”的定義
嘗試將 SQLite 用於我的應用程序時,Dotnet Core Web API 拋出
DbContextOptionsBuilder’不包含’UseSqlite’的定義並且沒有可訪問的擴展方法’UseSqlite'
如何解決這個問題?
我試過使用.Microsoft.EntityFrameworkCore;
使用 Microsoft.EntityFrameworkCore;
我通過添加 SQLite 包解決了這個問題。
在你的啟動文件上使用這個
using Microsoft.EntityFrameworkCore;在你的項目文件上使用這個
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.1"/>那麼你就可以使用 SQLite了
services.AddDbContext<DataContext>(x => x.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
如果您收到此錯誤,您可能忘記安裝Microsoft.EntityFrameworkCore.Sqlite包
在 Visual Studio 中,轉到工具 > NuGet 包管理器 > 包管理器控制台並鍵入:
Install-Package Microsoft.EntityFrameworkCore.Sqlite或者,如果您使用的是 .NET CLI,請在 shell 中鍵入:
dotnet add package Microsoft.EntityFrameworkCore.Sqlite該命令還會將相應的
<PackageReference ..>標籤添加到 RedWan 提到的項目文件中。