EF Code First,entity framework.数据表发生改变后如何处理

spqiweiguo 2019-05-12 10:01:54
如题:数据库表如果有变动,code first模式,如何和数据库表同步,用add-migration update-database 会报错:表已存在,删了重建会数据丢失.
...全文
477 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
spqiweiguo 2019-05-23
  • 打赏
  • 举报
回复
已找到完美的解决方法
spqiweiguo 2019-05-20
  • 打赏
  • 举报
回复
数据库表变动,比如增加个字段,这样只有手动在model里增加与其对应的属性,在执行数据迁移,后报错表已存在,遇到这种情况怎么办?
  • 打赏
  • 举报
回复
你不会程序里面以前的migration 都被你删除了吧?
那东西没上线前可以随便删,上线了还随便删是要出事的……
exception92 2019-05-13
  • 打赏
  • 举报
回复
数据表变动是什么变动,一般的变动的对象为Column。 查询DropCreateDatabaseIfModelChanges和Seed
秋的红果实 2019-05-12
  • 打赏
  • 举报
回复
还可以自己写代码,同步到改变,但挺复杂的,又不经常用
秋的红果实 2019-05-12
  • 打赏
  • 举报
回复
数据迁移 原有数据可以提前备份
Microsoft’s principal data access technology, ADO.NET Entity Framework, has had two major releases as part of the .NET Framework. NET 3.5 brought us the first version of Entity Framework, which is covered in the first edition of Programming Entity Framework. In 2010, Microsoft .NET 4 was released; it contained the next version of Entity Framework, referred to as Entity Framework 4. The completely revised second edition of Programming Entity Framework was dedicated to teaching readers how to use this version of Entity Framework in Visual Studio 2010. When .NET 4 was released, the Entity Framework team was already hard at work on a new addition, called Code First, to provide an alternative to building the Entity Data Model that is core to Entity Framework. Rather than using a visual designer, Code First allows you to create the model from your existing classes. This book is dedicated to teaching readers how to use Code First to build and configure a model based on the classes in your business domain. While Code First can do much of the job of inferring a model from your classes, there is quite a lot that you can do to affect the model that Code First creates. In this book, you will learn what Code First does by default (aka convention) and how to perform further configuration to affect how it understands your properties, classes, relationships, and the database schema they map to—whether you use Code First to help create a database or you want to use it with an existing database. With this knowl- edge, you can reap the benefits of the Entity Framework while leveraging existing classes or those classes you might be building for a new software project

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧