포기합니다. 찾았습니다. http://blogs.msdn.com/b/adonet/archive/2011/03/15/ef-4-1-model-amp-database-first-walkthrough.aspx 그리고 멋지다고 생각했습니다. 그래서 두 모델의 장점을 최대한 활용하기 위해 모델을 신속하게 재 설계했습니다.DbContext에서 첫 번째 모델, 새 데이터베이스를 초기화하지 못함
그러나 지금 내 모델은 새 데이터베이스를 만들거나 기존 테이블에 테이블을 추가하지 못합니다.
Code generated using the T4 templates for Database First and Model First development may not work correctly if used in Code First mode. To continue using Database First or Model First ensure that the Entity Framework connection string is specified in the config file of executing application. To use these classes, that were generated from Database First or Model First, with Code First add any additional configuration using attributes or the DbModelBuilder API and then remove the code that throws this exception.
에서 : 이 오류 얻을
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
을 그리고 내 연결 문자열입니다 :
<add name="ForumContextContainer"
providerName="System.Data.SqlClient"
connectionString="Data Source=.\SQLExpress; Initial Catalog=iForum; Integrated Security=True"/>
참고. 초기 카탈로그를 나중에 추가했는데 작동하려면 시도했지만 정확히 동일했습니다.
실제로 T4 템플릿을 chaning하여 주변을 발견했습니다. 어쨌든 덕분에 –
@ Łukasz Baran이 해결책을 공유해 주시겠습니까? –
@JoelBeckham 내 문제는 새로운 UnintentionalCodeFirstException(); 던졌습니다. Entities 클래스에서. – Saber