Pet*_*ter 3 c# sql-server entity-framework
我有2个解决方案,使用EF 6.0,并且都使用完全相同的默认配置。它们仍然连接到2个不同的数据源!(localdb)\ mssqllocaldb和。\ SQLEXPRESS。
我的配置:
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
两者的DbContext也相似:
public class PlusUltraContext : DbContext
{
    public PlusUltraContext() : base("PlusUltra")
    {
    }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        base.OnModelCreating(modelBuilder);
    }
    public DbSet<Models.Article> Articles { get; set; }
    public DbSet<Models.ArticleComment> Comments { get; set; }
}
与
public class InvoicingContext : DbContext
{
    public DbSet<Address> Addresses { get; set; }
    public DbSet<Company> Companies { get; set; }
    public DbSet<Country> Countries { get; set; }
    public DbSet<Currency> Currencies { get; set; }
    public DbSet<Invoice> Invoices { get; set; }
    public DbSet<InvoiceLine> InvoiceLines { get; set; }
    public DbSet<Person> Persons { get; set; }
    public DbSet<Unit> Units { get; set; }
    public InvoicingContext() : base("Invoicing")
    {
    }
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
        base.OnModelCreating(modelBuilder);
    }
}
但是,当我运行Update-Database命令时,第一个项目连接到。\ SQLEXPRESS,而另一个项目连接到(localdb)\ mssqllocaldb
目标数据库是:“ PlusUltra”(数据源:(localdb)\ mssqllocaldb,提供程序:System.Data.SqlClient,来源:Convention)。
与
目标数据库是:“发票”(数据源:。\ SQLEXPRESS,提供程序:System.Data.SqlClient,来源:约定)。
我的问题
我可以检查哪些内容以查看它们为何表现不同?
由于这篇文章,我找到了答案:
EF6找不到LocalDBConnectionFactory
在使用。\ SQLEXPRESS的解决方案中,启动项目是另一个类库,该类库不包含EF配置文件。将启动项目设置为包含配置文件的启动项目后,一切按预期进行,并且使用了mssqllocaldb。