par*_*ent 5 sql entity-framework azure ef-code-first azure-sql-database
我似乎无法让我的Code-First Migration创建我的SQL Azure数据库.
它一直在抱怨SQL Azure缺乏对没有聚簇索引的表的支持,我无法找到创建数据库的方法.
注意:我CreateDatabaseIfNotExists用于在第一次创建数据库时创建更改跟踪表,因为显然DropCreateDatabaseIfModelChanges 不会为您执行此操作
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");
}
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试"更新 - 数据库,我得到
Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.
Run Code Online (Sandbox Code Playgroud)
未创建数据库.
更新:我从头开始并按照本指南启用自动迁移(划伤数据库并以不存在的数据库启动,因此我不必从初始迁移中删除Up/Down代码)
这次我的数据库已成功创建(之前没有这么做),但是没有创建表,我仍然得到与以前相同的错误,不支持没有聚簇索引的表.
请指教
| 归档时间: |
|
| 查看次数: |
3626 次 |
| 最近记录: |