Thursday, September 14, 2017

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.

This error comes up when attempting to talk to an .edmx in lieu of going Code First with Entity Framework (i.e. Model First or Database First) and having a connection string that is not formatted in a Model First friendly way. The following is an example of the right was of talking to an .edmx named Foo.edmx in a Models folder somewhere:

<add name="FooEntities" connectionString="metadata=res://*/Models.Foo.csdl|res://*/Models.Foo.ssdl|res://*/Models.Foo.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=www.example.com;initial catalog=whatever;User ID=god;Password=letmein;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient"/>

 
 

Note that what you might normally think of as the connection string is wrapped in &quot; bookends and there is some extra gunk wrapping it.

No comments:

Post a Comment