【问题标题】:UseSqlite with Entity Framework Core in ASP.NET Core 2.1 not working在 ASP.NET Core 2.1 中使用带有实体框架核心的 Sqlite 不起作用
【发布时间】:2018-11-25 21:20:25
【问题描述】:

我正在 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吗?
  • 我还尝试了 ASP.NET Core 2.1 框架错误:NU1107:检测到 Microsoft.EntityFrameworkCore 的版本冲突。将 Microsoft.EntityFrameworkCore 2.2.2 直接安装/引用到项目 xyz。

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


【解决方案1】:

您的项目似乎没有安装Microsoft.EntityFrameworkCore.Sqlite

【讨论】:

  • 有时就是这么简单。没有意识到我没有从 NuGet 获得 Microsoft.EntityFrameworkCore.Sqlite。
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-11
      • 2021-08-23
      • 1970-01-01
      • 2022-11-18
      • 2020-11-06
      相关资源
      最近更新 更多