sqlite - 在 ASP.NET Core 2.1 中使用 Entity Framework Core 的 UseSqlite 不起作用

标签 sqlite entity-framework-core asp.net-core-2.1

我正在 ASP.NET Core 2.1 中启动一个 Razor 页面项目。我正在尝试使用 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();
        }
    }
}

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

这还不支持吗?通读文档似乎是这样。我不确定这里还有什么问题。

最佳答案

看来你没有安装Microsoft.EntityFrameworkCore.Sqlite到项目。

关于sqlite - 在 ASP.NET Core 2.1 中使用 Entity Framework Core 的 UseSqlite 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50885572/

相关文章:

sql - 根据路径在关闭表中查找记录

asp.net-core - 发布 ASP.NET Core 应用程序时自动执行迁移

entity-framework - EF 核心 : Add custom LINQ in Up method of Migration class

c# - .NET Core X509Certificate2 使用(Windows/IIS、Docker、Linux下)

c# - 作为 Windows 服务运行时,ASP.Net Core 2.1 应用程序找不到 appsettings.json

php - MySQL从另一个表插入随机值

python - 如何使用 Python 在更新语句 sqlite3 中插入​​变量?

c++ - 无法链接到 SQLite3 静态库

c# - 在 EF Core 2.0 中使用 DataTable 作为表值参数

c# - HttpClientFactory 任务取消异常 : Unable to read data from the transport connection