완벽하게 로컬에서 작동하는 웹 프로젝트가 있습니다. 그러나 Azure의 게시 된 웹 사이트에서 SQL Azure 데이터베이스에 연결 문자열을 변경하면이 오류가 발생합니다.엔티티 프레임 워크는 로컬에서는 작동하지만 하늘빛에서는 작동하지 않습니다.
System.Data.Entity.Infrastructure.UnintentionalCodeFirstException: 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.
at MyClass.OnModelCreating(DbModelBuilder modelBuilder) in c:\a\src\MyProject\Model.Context.cs:line 25
at System.Data.Entity.Internal.LazyInternalContext.CreateModelBuilder()
at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
at System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.Select[TSource,TResult](IQueryable`1 source, Expression`1 selector)
내 구성이 있습니다
<connectionStrings>
<add name="MyDBEntities" connectionString="metadata=res://*/MyModel.csdl|res://*/MyModel.ssdl|res://*/MyModel.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:[Removed].database.windows.net,1433;Database=MyDB;User ID=[Removed];Password=[Removed];Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"" providerName="System.Data.EntityClient" />
<add name="MyDB" connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string="Server=tcp:[Removed].database.windows.net,1433;Database=MyDB;User ID=[Removed];Password=[Removed];Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"" providerName="System.Data.EntityClient" />
</connectionStrings>
은 그 연결 문자열을 사용하여 로컬 내 단위 테스트를 사용하여 테스트 그리고 SQL 애저 데이터베이스에 연결 내 로컬 컴퓨터에서 작동합니다. 도움을 주시면 감사하겠습니다.
먼저 코드를 사용하고 있습니까? 먼저 모델을 먼저 사용합니까, 아니면 데이터베이스를 먼저 사용합니까? 또한 연결 문자열이 어떻게 표시됩니까 (자격 증명을 생략 할 수 있습니까)? –
연결 문자열은 모델을 어떻게 든 사용하고 있음을 나타냅니다 (모델 우선 또는 데이터베이스 우선). 어떻게 든 코드 우선을 사용하고 있습니까? 실수로 코드 접근법에서 실수로 코드를 사용할 수있는 방법에 대한 블로그 게시물을 찾았습니다. http://blog.oneunicorn.com/2012/02/26/dont-use-code-first-by-mistake/ –
' 코드를 먼저 사용하지 마십시오. 데이터베이스를 먼저 가지고 모델을 생성하는 데 사용했습니다. 나중에 모델을 약간 변경하고 데이터베이스를 업데이트해야했습니다. 리플렉터를 사용하여 DAL dll을 검사했으며 리소스에 csdl, msl 및 ssdl이 있습니다. – Mohsen