我正在尝试在控制台应用程序中配置实体框架7。

但是,我注意到在DbContextOptionBuilder中未定义“ UseSqlServer”

这是代码

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();
            });
        }
    }


我使用Nuget添加了EF 7“ install-packageEntityframework.commands -pre”

我正在使用Microsoft EF 7文档中的示例代码
不知道我在这里缺少什么。

-艾伦-

最佳答案

您需要安装Sql Server提供程序:https://www.nuget.org/packages/EntityFramework.MicrosoftSqlServer/7.0.0-rc1-final

关于c# - DbContextOptionBuilder中未定义UseSqlServer,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36951010/

10-11 15:17