teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

数年前に習作で書いてた、開発時LocalDB、リリース時AzureDBのEntityFrameworkのCodeFirstのWeb\.configを見つけたので貼っておく

2017/06/21 07:13

投稿

dojikko
dojikko

スコア3939

answer CHANGED
@@ -8,4 +8,39 @@
8
8
  > web.configのentityFrameworkの記述はコメントアウト済
9
9
 
10
10
  の意図がよくわかりませんが、EntityFramework CodeFirstを使っているならコメントアウトしてはいけないと思いますよ
11
- 接続先を切り替えても同じように動くのが大きなメリットなのに、「試したこと」のような作業がもし必要だとしたら良さがスポイルしていますよね
11
+ 接続先を切り替えても同じように動くのが大きなメリットなのに、「試したこと」のような作業がもし必要だとしたら良さがスポイルしていますよね
12
+
13
+ # 回答を追記(17/06/21)
14
+ 数年前に習作で書いてた、開発時LocalDB、リリース時AzureDBのEntityFrameworkのCodeFirstのWeb.configを見つけたので、今回の話題に絡みそうなところだけ貼っておきます
15
+ その当時はこれで動作しました
16
+ ```
17
+ <configSections>
18
+ <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
19
+ <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
20
+ </configSections>
21
+
22
+ <entityFramework>
23
+ <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
24
+ <parameters>
25
+ <parameter value="mssqllocaldb" />
26
+ </parameters>
27
+ </defaultConnectionFactory>
28
+ <providers>
29
+ <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
30
+ </providers>
31
+ </entityFramework>
32
+ ```
33
+
34
+ ## Web.Debug.configに書いたLocalDBの設定
35
+ ```
36
+ <connectionStrings>
37
+ <add name="DatabaseContext" connectionString="Data Source=(localdb)\v11.0;Integrated Security=True;AttachDbFileName=C:\UserDocument\App\Book.mdf;" providerName="System.Data.SqlClient" />
38
+ </connectionStrings>
39
+ ```
40
+
41
+ ## Web.Release.configに書いたAzureDBの設定
42
+ ```
43
+ <connectionStrings>
44
+ <add name="DatabaseContext" connectionString="Data Source=tcp:whm****gqh.database.windows.net,1433;Initial Catalog=SQLDB;User ID=user@whm****gqh;Password=Password" providerName="System.Data.SqlClient" />
45
+ </connectionStrings>
46
+ ```