冯 海

一个程序新人菜鸟的日记,希望大家多多关照。QQ:32316131

手动删除表后,怎么用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

成功。

posted @ 2017-06-18 15:16  秋天来了哟  阅读(336)  评论(0)    收藏  举报
认识就是缘份,愿天下人都快乐!
QQ: 32316131
Email: 32316131@qq.com