使用Sqlite ASP.NET Core 2.1中的实体框架核心不起作用



我正在 ASP.NET Core 2.1中启动一个Razor页面项目。我正在尝试使用SQLite,但是在配置数据库时,似乎只有SQL Server是一种选择。

启动.cs

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Application.Models;
using Microsoft.EntityFrameworkCore;
namespace Application
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationContext>(options =>
options.UseSqlite("Data Source=Database.db"));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseStaticFiles();
app.UseMvc();
}
}
}

智能感知无法识别options.UseSqlite并且生成失败。这不是/不是.net core 2.0项目的问题。

这还不支持吗?通读文档会发现确实如此。我不确定这里还有什么问题。

您似乎尚未将Microsoft.EntityFrameworkCore.Sqlite安装到项目中。

我也有同样的问题,但在安装软件包后Install-Package Microsoft.EntityFrameworkCore.Sqlite -Version 2.1.1

从Nuget安装Microsoft.EntityFrameworkCore.Sqlite包,并确保包版本也与目标框架版本兼容。

最新更新