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-
You need to install the SqlServer provider: https://www.nuget.org/packages/EntityFramework.MicrosoftSqlServer/7.0.0-rc1-final
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.