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

uelo1irk  于 2022-12-13  发布在  SQLite
关注(0)|答案(3)|浏览(195)

我正在ASP.NETCore2.1中启动一个RazorPages项目。我试图使用SQLite,但在配置数据库时,似乎只有SQLServer是一个选项。

启动.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项目的问题。
这是不是还不受支持?阅读文档后发现似乎是的。我不确定还有什么地方出了问题。

2skhul33

2skhul332#

我也有同样的问题,但在安装包 * 安装包Microsoft.EntityFrameworkCore.Sqlite -版本2.1.1*

p8ekf7hl

p8ekf7hl3#

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

相关问题