手动删除表后,怎么用ef自动first code 建表
这个问题,搞了几个小时,莫名的好了,
我赶快记下来
1.Enable-Migrations -ContextTypeName jsdhh2.DAL.OaDALContent -Force
2. add-migration AddOaDALContentTable
这中间会新建所有的表,删除不要的,留 我需要的
using System;
using System.Data.Entity.Migrations;
public partial class AddOaDALContentTable : DbMigration
{
public override void Up()
{
CreateTable(
"dbo.Arrears1",
c => new
{
Id = c.String(nullable: false, maxLength: 128),
SerialNumber = c.Int(nullable: false),
UserName = c.String(),
Number = c.Long(nullable: false),
AccountId = c.String(),
ContactNumber = c.Long(nullable: false),
Product = c.String(),
Package = c.String(),
AmountMoney = c.Double(nullable: false),
Aging = c.Int(nullable: false),
Address = c.String(),
PayType = c.String(),
ResponsibleDePart = c.String(),
ResponsiblePeople = c.String(),
Bei = c.String(),
})
.PrimaryKey(t => t.Id);
CreateTable(
"dbo.Arrears2",
c => new
{
Id = c.String(nullable: false, maxLength: 128),
SerialNumber = c.Int(nullable: false),
UserName = c.String(),
Number = c.Long(nullable: false),
AccountId = c.String(),
ContactNumber = c.Long(nullable: false),
Product = c.String(),
Package = c.String(),
AmountMoney = c.Double(nullable: false),
Aging = c.Int(nullable: false),
Address = c.String(),
PayType = c.String(),
ResponsibleDePart = c.String(),
ResponsiblePeople = c.String(),
Bei = c.String(),
})
.PrimaryKey(t => t.Id);
}
public override void Down()
{
DropTable("dbo.Arrears2");
DropTable("dbo.Arrears1");
}
}
3.update-database
成功。
浙公网安备 33010602011771号