使用 Entity Framework Code First 更改 table(添加列)的最便捷方式?

Most convenient way to alter table (add column) using Entity Framework Code First?

我使用 Code First Entity Framework 6.0 方法并且有 BaseClass 和一些 DerivedClasses。我曾经手动更新数据库(所有表都来自 BaseClass)。

我想更新(无论在哪里)数据 1 次。

类:

public class IItem {

    public int Id {
        get;
        set;
    }

    public string Model {
        get;
        set;
    }

    public int Cost {
        get;
        set;
    }

    //other properties

}


public class MotherBoard : IItem {

    public string Manufacturer {
        get;
        set;
    }

    public string FormFactor {
        get;
        set;
    }

    public string CPUManufacturer {
        get;
        set;
    }

    public string Socket {
        get;
        set;
    }

    public int SocketCount {
        get;
        set;
    }

    //other properties

}

//there are 3 more classes

EF 上下文:

public class EFDbContext : DbContext {

    public IDbSet<MotherBoard> MotherBoards {
        get;
        set;
    }


    public IDbSet<Processor> Processors {
        get;
        set;
    }


    public IDbSet<VideoCard> VideoCards {
        get;
        set;
    }


    //other

}

你好,你能 post 你的 class 和上下文 class 的代码吗?

您使用的是什么版本的 EF,在什么情况下使用?

你只有一个上下文吗?如果是这样,请尝试在 PowerShell 中同时使用您的上下文定位项目

启用迁移
添加迁移初始
更新数据库