Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbContextBuilder does not contain definition for UseSqlite

I'm new to UWP and I'm trying to set up my project to use SQLite database, I'm making use of the Microsoft.EntityFrameworkCore.SQLite.

When I try to set up the database context, I keep getting this error.

DbContextOptionsBuilder does not contain definition for UseSqlite and no accessible extension method accepting a first argument of type DBcontextoptionsbuilder could be found (are you using directive or assembly reference)

Here's my code

using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BradamaInternationalSkill.Models
{
    /// <summary>
    /// The Entity Framework Database Context.
    /// </summary>
    public class PersonContext : DbContext
    {
        internal DbSet<Person> People { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            optionsBuilder.UseSqlite("Filename=People.db");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // Make Id required.
            modelBuilder.Entity<Person>()
                .Property(p => p.Id)
                .IsRequired();

            // Make Name required.
            modelBuilder.Entity<Person>()
                .Property(p => p.Name)
                .IsRequired();
        }
    }
}
like image 528
Gabbywells Avatar asked Sep 08 '18 20:09

Gabbywells


1 Answers

I solved the issue by uninstalling the Nuget package "Microsoft Entity Framework Core" and installing "Entity.Framework.Core.Sqlite.Design". I don't know why it solved the issue but the error is gone, I'm happy and that's all that matters.

like image 72
Gabbywells Avatar answered Oct 16 '22 14:10

Gabbywells