使用Entity Framework Code First更改表(添加列)最方便的方法?

时间:2015-07-03 18:10:57

标签: c# entity-framework ef-code-first

我使用Code First Entity Framework 6.0方法并拥有BaseClass和一些DerivedClass es。我曾经手动更新数据库(所有来自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 context:

public class EFDbContext : DbContext {

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


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


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


    //other

}

1 个答案:

答案 0 :(得分:1)

您可以发布您的类和上下文类的代码吗?

您使用EF的版本以及在什么情况下?

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

启用的迁移
add-migration初始
更新的数据库

相关问题