c# - Costumize DbContext using connection string from ServiceConfiguration (Azure) -
i using entity-framework code first approach , have custom dbcontext. connectionstring defined in serviceconfiguration.cloud.cscfg , serviceconfiguration.local.cscfg files.
public customcontext() : base("dbactivity") { ...
when above code executes, tries check web.config , not serviceconfiguration file azure solution.
update: here connectionstring in serviceconfiguration file:
<configurationsettings> <setting name="microsoft.windowsazure.plugins.diagnostics.connectionstring" value="usedevelopmentstorage=true" /> <setting name="dbactivity" value="server=tcp:xxx.database.windows.net,1433;database=ra;user id=user;password=password;trusted_connection=false;encrypt=true;connection timeout=30;" /> </configurationsettings>
exception:
no connection string named 'server=tcp:xxx.database.windows.net,1433;database=ra;user id=user;password=password;trusted_connection=false;encrypt=true;connection timeout=30;' found in application config file."
is possible create check serviceconfiguration.local.cscfg instead?
finally found solution. it's necessary utilize sqlconnectionstringbuilder class.
public raactivitycontext() : base((new sqlconnectionstringbuilder( cloudconfigurationmanager.getsetting("dbraactivity")).tostring())) { }
c# entity-framework azure
No comments:
Post a Comment