[英]Using Entity Framework Code First Development, can I get it to create a table or tables in an existing database?
I'm new to Entity Framework, and I have an existing database that I'd like to add a few tables to, rather than creating a database from scratch for my new tables. 我是Entity Framework的新手,我有一个现有数据库想要添加一些表,而不是从头开始为新表创建数据库。 Is this possible with Entity Framework?
使用实体框架可以做到吗?
I've looked through the following MSDN articles on Code First development, and haven't been able to find the answer to my issue: 我浏览了有关Code First开发的以下MSDN文章,但找不到我的问题的答案:
I have had the same experience with my asp.net mvc3 project, it's a little different from asp.net but I guess entity framework is the focus here. 我在asp.net mvc3项目中有相同的经验,它与asp.net略有不同,但是我想这里重点关注实体框架。
create new table in sql server 在SQL Server中创建新表
create corresponding model in your model project 在模型项目中创建相应的模型
Add the new table object property in DbNameEntities.cs 在DbNameEntities.cs中添加新的表对象属性
public DbSet NewTables { get; 公共DbSet NewTables {get; set;
组; }
}
In Application_Start() method, comment out the original code first approach 在Application_Start()方法中,注释掉原始代码优先方法
System.Data.Entity.Database.SetInitializer(new SeedSampleData()); System.Data.Entity.Database.SetInitializer(new SeedSampleData());
replace with this: 替换为:
System.Data.Entity.Database.SetInitializer<DbNameEntities>(null);
Yes, this is certainly possible. 是的,这肯定是可能的。
A decent walk-through is available on Scott Gu's blog Scott Gu的博客提供了不错的演练
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.