Azureはじめました

Windows Azureで業務システムを組んでみる日記

Controller/Viewのスキャフォールディング中にエラー

f:id:twisted0517:20150301182128p:plain

これで何をわかれと言うのか(# ゚Д゚)

In my case I moved my connection strings out of the Web.config to

<connectionStrings configSource="ConnectionStrings.config"/> 

that when I started getting the error when I was trying to scaffold.

There was an error running the selected code generator: ‘Exception has been thrown by the target of an invocation.’

Moving my connection strings back to the Web.config solved my issue.

c# - Application can't scaffold items - Stack Overflow

あっ

原因

今やってるプロジェクトではDataContextに独自拡張するために、

DbContext 
| 
+-- HogeProjectEntities ←EFで作られた基本となるDataContext
      |
      +--- ProjectEntities ←プロジェクトで使うDataContext

という構成になってる。
更に、ローカルとAzureでConnectionStringを分けるために環境ごとのConnectionStringローダーを作って、ProjectEntitesのコンストラクタで参照してる。
この環境ごとのConnectionStringを取得するために

public static string connectionString {
    get {
        string connectionStringName =
                RoleEnvironment.GetConfigurationSettingValue("HogeProject.database.ConnectionString");

        return ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
    }
}

と、RoleEnvironmentを元に参照しWeb.Configのエントリを引っ張りだしてる。

これが開発時に使えないという事か。

しかし

スキャフォールディングに何でインスタンス化するのか納得できん。
何のためのリフレクションなんだよ。

(# ゚Д゚)プンスコ