我创建了新项目,并为其添加了最新的实体框架(版本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