2012-11-06 4 views
3

다른 컨텍스트에서 상속되는 컨텍스트에서 엔터티 구성을 수정하거나 바꿀 수 있습니까?코드 첫 번째 EntityConfiguration

예 : Framework라는 솔루션에서 Data.Access라는 프로젝트에 Context가 있습니다. 내가 프레임 워크 솔루션에 Data.Access에서 컨텍스트를 확장하는 컨텍스트 클래스가있는 Local.Data.Access 프로젝트가, FrameworkConsumer라는 또 다른 솔루션에서

protected override void OnModelCreating(DbModelBuilder modelBuilder) 
{ 
    // TestEntityConfiguration is the configuration of an entity named TestEntity in the Framework solution 
    modelBuilder.Configurations.Add(new TestEntityConfiguration()); 

    // multiple other configurations... 
} 

: 그 OnModelCreating 기능은 엔티티 thusly 히 구성을 추가합니다. 그 OnModelCreating 함수는 다음과 같습니다 :

내 질문은 이것입니다. FrameworkConsumer 솔루션의 Local.Data.Access 프로젝트에서 추가 구성 설정이나 TestEntity의 다른 구성을 추가하려면 어떻게 수행 할 수 있습니까? 그러나 다른 구성을 추가하려고 시도했지만이 Entity (TestEntity)가 이미 구성되었다는 오류가 표시됩니다. 당분간, 추가 구성을 추가하는 나의 해결책은 Local.Data.Access 컨텍스트 클래스의 Dispose 함수에서 Database.ExecuteSqlCommand를 사용하는 것입니다. 우아하지 않지만 작동합니다. 모든 아이디어/조언을 부탁드립니다.

감사

답변

0

당신은 당신이 그것을 변경해야하는 경우 재정의 할 수있는 또 다른 가상 메서드에 해당 구성을 넣을 수 있습니다. 예 :

protected override void OnModelCreating(DbModelBuilder modelBuilder) 
{ 
    // multiple other configurations... 
    SpecialConfigurations(modelBuilder);  

} 

protected virtual void SpecialConfigurations(DbModelBuilder modelBuilder) 
{ 
    // TestEntityConfiguration is the configuration of an entity named TestEntity in the Framework solution 
    modelBuilder.Configurations.Add(new TestEntityConfiguration()); 

    // multiple other configurations... 
} 

그런 다음 SpecialConfigurations 메서드를 재정의합니다.