我似乎无法通过代码优先迁移来创建 SQL Azure 数据库。
它一直抱怨 SQL Azure 缺乏对没有聚集索引的表的支持,而且我找不到创建数据库的方法。
Note:我在用着CreateDatabaseIfNotExists
在第一次创建数据库时创建更改跟踪表,因为显然DropCreateDatabaseIfModelChanges
不为你做那件事 https://stackoverflow.com/a/8630863/1267778
public partial class IUnityDbContext : DbContext
{
public IUnityDbContext()
: base("Name=IUnityDbContext")
{
Database.SetInitializer(new CreateDatabaseIfNotExists<IUnityDbContext>());
//Database.SetInitializer(new DropCreateDatabaseIfModelChanges<IUnityDbContext>());
}
public DbSet<User> Users { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new UserMap());
base.OnModelCreating(modelBuilder);
}
}
public partial class Initial : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Users",
c => new {
...
}
).PrimaryKey(u => u.UserId, clustered: true);
}
public override void Down()
{
DropTable("dbo.Users");
}
}
如果我尝试“更新数据库”我得到
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
数据库未创建。
UPDATE:我从头开始并遵循本指南 http://geekswithblogs.net/michelotti/archive/2012/11/13/enable-automatic-code-first-migrations-on-sql-database-in-azure.aspx启用自动迁移(划伤数据库并从不存在的数据库开始,这样我就不必从初始迁移中删除向上/向下代码)
这次我的数据库已成功创建(之前没有做到这一点),但是表没有创建,我仍然得到与以前相同的错误,即不支持没有聚集索引的表。
请指教
事实证明这是 Entity Framework 6 -Alpha 3 中的一个错误。我想我应该提到这一点。
https://stackoverflow.com/a/15282861/1267778 https://stackoverflow.com/a/15282861/1267778
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)