UseSqlite with Entity Framework Core in ASP.NET Core 2.1 not working

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

Question

I am starting a Razor pages project in ASP.NET Core 2.1. I am trying to use SQLite but when configuring the database only SQL Server seems to be an option.

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 does not recognize options.UseSqlite and builds fail. This was not/ is not an issue with .net core 2.0 projects.

Is this not supported yet? Reading through the documentation makes it seem that it is. I'm not sure what else is going wrong here.

1
5
6/16/2018 7:35:05 AM

Accepted Answer

It’s seems that you have not installed Microsoft.EntityFrameworkCore.Sqlite to the project.

20
6/16/2018 7:05:14 AM

Popular Answer

I also had same issue but after installing package Install-Package Microsoft.EntityFrameworkCore.Sqlite -Version 2.1.1



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow