UseSqlServer is not defined in DbContextOptionBuilder

c# entity-framework entity-framework-core visual-studio-2015


I am trying to configure entity framework 7 in my console application.

However , I noticed that "UseSqlServer" is not defined in DbContextOptionBuilder

Here is the code

public class LetsBreakITContext : DbContext
        public DbSet<Book> Books { get; set; }
        public DbSet<Country> Countries { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

        protected override void OnModelCreating(ModelBuilder modelBuilder)
            modelBuilder.Entity<Country>(c =>
               c.HasKey(e => e.CountryId);
               c.Property(e => e.CountryId).ValueGeneratedOnAdd();
               c.Property(e => e.CountryId).IsRequired();
               c.Property(e => e.Name).IsRequired();
            modelBuilder.Entity<Book>(l =>
                l.HasKey(e => e.BookId);
                l.Property(e => e.BookId).ValueGeneratedOnAdd();
                l.Property(e => e.CountryId).IsRequired();
                l.Property(e => e.Name).IsRequired();

I added EF 7 using Nuget "install-package entityframework.commands -pre"

I am using the sample code from Microsoft's EF 7 documentation Not sure what I am missing here.


4/30/2016 5:09:44 AM

Accepted Answer

5/1/2016 6:51:06 AM

Popular Answer

If you want to use MS SQL server, add Microsoft.EntityFrameworkCore.SqlServer nuget package to your project Microsoft.EntityFrameworkCore.SqlServer

I'm using .NET Core 2.0. I used: Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 2.0.0

And it works for me.

Related Questions


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