我創建了一個項目通話Repository.EF來處理一個正解的輪胎數據訪問。我已經將EF添加到了Repository.EF項目中,我擁有了所有POCO的項目。然後我在這個項目中創建了一個DbContext類。我的連接字符串在哪裏?
namespace LearningSpike.Repositories.EF
{
class GlassContractDbContext:DbContext
{
public GlassContractDbContext() : base("GlassContractContext")
{
}
public DbSet<MetalStock> MetalStock { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Configurations.Add(new MetalStockConfiguration());
}
}
隨後前往包管理器控制檯,並做了
Enable-Migrations
然後設置
AutomaticMigrationsEnabled = true;
然後
Update-Database
一切工作正常。但問題是,我不知道連接字符串在哪裏。看起來好像這個特定項目中沒有connectionString。我知道,如果我有一個MVC4/5模板,將有在web.config一個的connectionString。我怎樣才能找到連接字符串? 現在如何配置?舉例來說,我記得在MVC5應用程序中使用connectionString來做這件事。
MultipleActiveResultSets=true
現在我該怎麼做?
謝謝! 乾杯!
PS
我也有我的App.config下面的代碼在Repository.EF項目
<?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" />
<!-- For more information on Entity Framework configuration, visit
http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<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>
你的連接字符串應該在web項目的web.config – InferOn
嗨,感謝您的快速回復。但是,問題是,這個項目中沒有web.config。這個項目只是一個班級庫,我擁有我所有的POCO。所以我加了EF。這個想法是保持這個層分離,並將其用於數據訪問。 –
你單獨的類庫會在某些應用中,爲了工作,所以它會使用連接字符串從「主機」應用程序加載。 – Fedor