UseSqlServer is not defined in DbContextOptionBuilder

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

Question

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)
        {
            optionsBuilder.UseSqlServer(@"Server=(localdb)\mssqllocaldb;Database=EFGetStarted.ConsoleApp.NewDb;Trusted_Connection=True;");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            //country
            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();
           });
            //Book
            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.

-Alan-

1
2
4/30/2016 5:09:44 AM

Accepted Answer

6
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





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