【发布时间】:2016-08-04 03:03:33
【问题描述】:
我正在尝试使用实体框架来update-database。
它运行良好,没有错误。当我使用-Verbose 时,它会显示
Target database is: 'PokemonAppCore.PkmnContext' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention)
但在app.config 中,我已将其指向本地数据库,就像这样。 LocalDb 下的 SQL Server Explorer 中没有显示任何内容。
为什么它使用.\SQLEXPRESS 而不是localdb,就像在app.config 中指定的那样?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</configSections>
<connectionStrings>
<add name="PkmnConnectionString"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=PkmnDatabase;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
【问题讨论】:
-
你是否将 PkmnConnectionString 传递给 DbContext 构造函数
-
不,我以为我不必这样做,因为它是从 app.config 读取的?
-
您必须将 PkmnConnectionString 传递给 DbContext
标签: c# sql-server entity-framework database-connection