提供者没有使用 Code First 方法 return WPF 中的 ProviderManifestToken 字符串

the provider did not return a ProviderManifestToken string in WPF using Code First Approach

我想知道我应该写什么来创建我的数据库,因为在我的应用程序 运行 上,仍然没有创建数据库。我想在 Visual Studio 2013 年创建本地数据库。

这是我的上下文class

class dbContext : DbContext
{
    public dbContext()
    {
        Database.SetInitializer<dbContext>(new DropCreateDatabaseIfModelChanges<dbContext>());
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        base.OnModelCreating(modelBuilder);
        modelBuilder.Conventions.Remove<System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention>();
    }

    public DbSet<Employee> Employee { get; set; }
    public DbSet<Credit> Credit { get; set; }
    public DbSet<Debit> Debit { get; set; }
    public DbSet<Salary> Salary { get; set; }
    public DbSet<Category> Category { get; set; }
}

这是主要的-Class

public partial class MainWindow
{
    public MainWindow()
    {
        InitializeComponent();
        Database.SetInitializer<dbContext>(null);
    }

    private void btn_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            dbContext context = new dbContext();
            Category c = new Category();
            c.Id = 1;
            c.Name = "Category";
            c.TotalExpenses = 0;

            context.Category.Add(c);
            context.SaveChanges();
            btn.Content = context.Category.SingleOrDefault(x => x.Id == 1);
        }
        catch (Exception ex)
        {
            while (ex.InnerException != null)
            {
                ex = ex.InnerException;
                MessageBox.Show(ex.Message);
            }
            MessageBox.Show(ex.Message);
        }
    }
}

这里是connectionString

<connectionStrings>
    <add name="dbContext"
         connectionString="server=.; database=sample; Integrated Security=true"
         providerName="System.Data.SqlClient"/>
</connectionStrings>

当我尝试在数据库 table 中保存一些值时,它仍未创建,

exception occurs "the provider did not return a ProviderManifestToken string"

other Exception below in image

我应该怎么做才能解决这个问题。

将您的连接字符串更改为:

<connectionStrings>
<add name="dbContext"
     connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=sample;Integrated Security=SSPI" providerName="System.Data.SqlClient""/>