[英]Most convenient way to alter table (add column) using Entity Framework Code First?
I use Code First Entity Framework 6.0 approach and have BaseClass
and some of DerivedClass
es. 我使用Code First Entity Framework 6.0方法,并具有
BaseClass
和一些DerivedClass
es。 I used to manually update database (all tables derived from BaseClass
). 我曾经手动更新数据库(所有从
BaseClass
派生的表)。
I want to update (doesn't matter where) data 1 time. 我想1次更新(无论在哪里)数据。
Classes: 类:
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: EF上下文:
public class EFDbContext : DbContext {
public IDbSet<MotherBoard> MotherBoards {
get;
set;
}
public IDbSet<Processor> Processors {
get;
set;
}
public IDbSet<VideoCard> VideoCards {
get;
set;
}
//other
}
Hi could you post your code for your classes and context class? 您好,您可以为自己的课程和上下文课程发布代码吗?
What versions are you using of EF and in what context? 您正在使用什么版本的EF,以及在什么情况下使用?
Do you have just the one context? 您只有一种情况吗? If so try in PowerShell whilst targeting the project with your context
如果是这样,请在PowerShell中尝试,同时根据您的上下文定位项目
enable-migrations 启用迁移
add-migration Initial 添加迁移初始
update-database 更新数据库
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.