簡體   English   中英

如何在實體框架遷移中使用localDb?

[英]How to use localDb with entity framework migrations?

我有Persistence類庫,其中包含我的DbContext類。 它還包含app.config文件,其中我具有以下預定義的連接字符串:

  <connectionStrings>
    <add name="<Namespace1>.Persistence.AssessmentContext" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\AssessmentContext.mdf;Integrated Security=True"
   providerName="System.Data.SqlClient" />
  </connectionStrings>

假設AssesmentContext具有Namespace1.Persistence空間。

當我嘗試使用PM控制台啟用遷移時,它給了我這樣的錯誤:

An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file.

當我嘗試對其進行調試並將調試輸出放入AssessmentContext ctor時,我發現連接字符串仍在使用。\\ SQLEXPRESS數據源。

Data Source=.\SQLEXPRESS;Initial Catalog=<Namespace1>.Persistence.AssessmentContext;Integrated Security=True;MultipleActiveResultSets=True

所以我做錯了什么? 以及為什么EF不從app.config中獲取我的連接字符串?

如果使用桌面應用程序,則必須將上述連接字符串條目復制到可執行程序的app.config中,如果使用Web應用程序,則必須復制到web.config中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM