Reputation: 2103
In my context class I have the following to make the project a black box for data.
public MyEntities()
: base("metadata = res://*/fda.csdl|res://*/fda.ssdl|res://*/fda.msl;provider=System.Data.SqlClient;provider connection string='data source=MyServer;initial catalog=CitywideEmployees;persist security info=True;user id=MyUserID;password=MyPassword!;MultipleActiveResultSets=True;App=EntityFramework'")
{
}
However when I update the edmx, using the "Update Model from Database" option, it always resets the base argument, almost like it wants to look in an App.config file for the connection string. How do I prevent having to update the base every time I update the edmx?
Thanks.
Upvotes: 0
Views: 281
Reputation: 2107
Open your {your name}.Context.tt and save the following change
<#=Accessibility.ForType(container)#> partial class <#=code.Escape(container)#> : DbContext
{
public <#=code.Escape(container)#>()
: base("name=<#=container.Name#>")
{
<#
In quotes where it says "name=<#=container.Name#>"
replace it with
<#=Accessibility.ForType(container)#> partial class <#=code.Escape(container)#> : DbContext
{
public <#=code.Escape(container)#>()
: base("metadata = res://*/fda.csdl|res://*/fda.ssdl|res://*/fda.msl;provider=System.Data.SqlClient;provider connection string='data source=MyServer;initial catalog=CitywideEmployees;persist security info=True;user id=MyUserID;password=MyPassword!;MultipleActiveResultSets=True;App=EntityFramework'")
{
<#
save your tt file
Upvotes: 1