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

ASP.NET Core 2.1中实体框架核心不起作用的UseSqlite,sqlite,entity-framework-core,asp.net-core-2.1,Sqlite,Entity Framework Core,Asp.net Core 2.1,我正在ASP.NET Core 2.1中启动一个Razor pages项目。我试图使用SQLite,但在配置数据库时,似乎只能选择SQL Server Startup.cs using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.E

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

Startup.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();
        }
    }
}
使用Microsoft.AspNetCore.Builder;
使用Microsoft.AspNetCore.Hosting;
使用Microsoft.AspNetCore.Mvc;
使用Microsoft.Extensions.Configuration;
使用Microsoft.Extensions.DependencyInjection;
使用应用程序模型;
使用Microsoft.EntityFrameworkCore;
命名空间应用程序
{
公营创业
{
公共启动(IConfiguration配置)
{
配置=配置;
}
公共IConfiguration配置{get;}
//此方法由运行时调用。请使用此方法将服务添加到容器中。
public void配置服务(IServiceCollection服务)
{
services.AddDbContext(选项=>
options.UseSqlite(“datasource=Database.db”);
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
//此方法由运行时调用。请使用此方法配置HTTP请求管道。
公共无效配置(IApplicationBuilder应用程序,IHostingEnvironment环境)
{
app.UseStaticFiles();
app.UseMvc();
}
}
}
Intellisense无法识别
选项。使用SQLite
生成失败。这不是.net核心2.0项目的问题


这是否还不受支持?通读文档会让人觉得是这样的。我不确定这里还出了什么问题。

您似乎还没有安装到项目中。

我也遇到了同样的问题,但在安装软件包之后
安装软件包Microsoft.EntityFrameworkCore.Sqlite-版本2.1.1

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

您安装了Microsoft.EntityFrameworkCore.Sqlite吗?我还尝试了ASP.NET Core 2.1框架错误:NU1107:检测到Microsoft.EntityFrameworkCore的版本冲突。直接将Microsoft.EntityFrameworkCore 2.2.2安装/引用到project xyz。有时就这么简单。没有意识到我没有从NuGet获得Microsoft.EntityFrameworkCore.Sqlite。