Create a WebAPI or MVC project with a Model First EF Dal. Everything works fine. Now migrate Database to Sql Azure, and MVC Project to Azure Website. It is not possible to "out of the box" configure the Azure Website to correctly instantiate and have the Azure Website with a Model First EF Dal successfully connect to the Sql Azure instance.
It is required that you need to manually build up the the connection string, then override the Context.tt file to allow passing in the built up connection string. Please find attached the modified .tt that takes care of this for you, thinking we could do a minor Pull request here and incorporate my .tt changes.
With this .tt you can use the code locally and on Azure in the following way
var dal = <EntitiesContainerName>.NewContext("<StandardSqlClientConnectionName>", "<QualifiedMetadataInformation>"))
for example
public ActionResult Test()
{
using ( var dal = RinconEntities.NewContext("Rincon", "Dal.RinconDb"))
{
//do something
}
}
It is required that you need to manually build up the the connection string, then override the Context.tt file to allow passing in the built up connection string. Please find attached the modified .tt that takes care of this for you, thinking we could do a minor Pull request here and incorporate my .tt changes.
With this .tt you can use the code locally and on Azure in the following way
var dal = <EntitiesContainerName>.NewContext("<StandardSqlClientConnectionName>", "<QualifiedMetadataInformation>"))
for example
public ActionResult Test()
{
using ( var dal = RinconEntities.NewContext("Rincon", "Dal.RinconDb"))
{
//do something
}
}