我創建了新項目,併爲其添加了最新的實體框架(版本4.3)。我在之前的EF版本中創建了類和上下文。但是,如果要創建數據庫的第一個運行期間(在我的情況下,它是SQL Server 2005中),我收到以下錯誤:實體框架4.3不創建數據庫
An error occurred while executing the command definition. See the inner exception for details.
用下面的內部異常:
Invalid object name 'dbo.__MigrationHistory'.
據我所知,該表適用於遷移,但如果沒有數據庫,則此表不存在。難道我做錯了什麼?
更多信息: 出於測試目的,我只創建一個類:
public class Test
{
[Key]
public int TestId { get; set;}
public string Name {get; set;}
}
public class Context : DbContext
{
public Context() : base("MyConnection")
{
}
public DbSet<Test> Tests { get; set;}
}
更新1
一些測試後,我意識到,應用程序從Visual Studio中拋出未處理的異常,並在視覺突破工作室。例外是System.Data.EntityCommandExecutionException。一旦我忽略了這種期望並且沒有停止代碼執行,就創建了數據庫。
更新2
使用數據庫的另一個幾個小時後,我發現,與啓用的遷移選項,並更新數據庫打從控制檯也就是解決這個問題。它在應用程序啓動之前創建數據庫,並且不會在Visual Studio中中斷。
看上去就像是失去同步 http://stackoverflow.com/questions/3986160/an-error-occurred-while-executing-the-command-definition-see-the-inner-exceptio – 2012-02-20 16:51:51
有你手動創建類?或者您已經使用了嚮導 – 2012-02-20 17:27:23
對於測試,我只創建了一個名爲Test的TestDef,名稱爲[Key],字符串屬性名爲name。沒有別的。 – Marcin 2012-02-20 17:45:33