Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 931
nick Avatar asked Jun 16 '18 06:06

nick


People also ask

Can I use Entity Framework with ASP NET core?

To use Entity Framework 6, your project has to compile against . NET Framework, as Entity Framework 6 doesn't support . NET Core. If you need cross-platform features you will need to upgrade to Entity Framework Core.

Can we use EDMX in .NET core?

EF Core does not support the EDMX file format for models.

Does net5 support Entity Framework?

NET Standard 2.1 platform. This means EF Core 5.0 will run on . NET Core 3.1 or . NET 5, as well as other platforms that support .


2 Answers

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

like image 50
vivek nuna Avatar answered Oct 07 '22 17:10

vivek nuna


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

like image 45
Raj Avatar answered Oct 07 '22 19:10

Raj