12

我正在 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();
        }
    }
}

Intellisense 无法识别options.UseSqlite并且构建失败。这不是/不是 .net core 2.0 项目的问题。

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

4

3 回答 3

35

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

于 2018-06-16T07:05:14.867 回答
1

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

于 2019-03-01T14:40:15.277 回答
0

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

于 2020-01-03T04:06:00.617 回答