我正在为我的应用程序设置非常基本的代码优先方法数据库上下文。我的解决方案下有MVC(UI)和类库(EntityFramework)项目。在Update-Database
上收到错误Instance failure.
//迁移配置
internal sealed class Configuration : DbMigrationsConfiguration<UrfPractice.EntityFramework.UrfPracticeDbContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
}
//数据库上下文
public class UrfPracticeDbContext : DbContext
{
static UrfPracticeDbContext()
{
Database.SetInitializer<UrfPracticeDbContext>(null);
}
public UrfPracticeDbContext() : base("name=DefaultConnectionString")
{
Configuration.AutoDetectChangesEnabled = true;
Configuration.LazyLoadingEnabled = true;
Configuration.ProxyCreationEnabled = false;
}
public DbSet<Entities.Customer> Customers { get; set; }
}
//客户迁移
public partial class Customer : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.tblCustomers",
c => new {
Id = c.Int(nullable: false, identity: true),
CustomerId = c.Int(nullable: false),
Fullname = c.String(nullable: false, maxLength: 256)
}).PrimaryKey(t => t.Id);
}
public override void Down()
{ DropTable("dbo.tblCustomers"); }
}
//实体类
[Table("tblCustomers")] public class Customer {
[Key]
public int CustomerId { get; set; }
[MaxLength(250)]
public string Fullname { get; set; }
}
屏幕截图=> https://user-images.githubusercontent.com/47334134/53000129-b4582800-3438-11e9-9d17-4f1903c5d623.png