n-tire 솔루션에서 데이터 액세스를 처리하기 위해 Repository.EF라는 프로젝트 호출을 만들었습니다. 나는 모든 POCO가있는 Repository.EF 프로젝트에 EF를 추가했습니다. 그런 다음이 프로젝트에서 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
을 한 다음
Update-Database
모든 것이 잘 작동 그런 다음
AutomaticMigrationsEnabled = true;
을 설정합니다. 하지만 문제는 연결 문자열이 어디에 있는지 모르겠습니다. 특정 프로젝트에 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.config에 있어야합니다. – InferOn
안녕하세요, 빠른 답장을 보내 주셔서 감사합니다. 그러나 문제는이 프로젝트에 web.config가 없다는 것입니다. 이 프로젝트는 모든 POCO가있는 클래스 라이브러리 일뿐입니다. 그래서 그것에 EF를 추가했습니다. 이 레이어를 별도로 유지하고 데이터 액세스 용으로 사용하는 것이 좋습니다. –
별도의 클래스 라이브러리가 작동하기 위해 일부 응용 프로그램에로드되므로 '호스트'응용 프로그램의 연결 문자열을 사용하게됩니다. – Fedor