EF Database首先如何为数据库更改更新模型? [英] EF Database first how to update model for database changes?

查看:378
本文介绍了EF Database首先如何为数据库更改更新模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在类库Ado.net Entity Data Model中已生成POCO类.这些是第一次产生罚款.但是,数据库更改没有得到反映.在edmx图中,右键单击并选择Update Model from Database显示新创建的表,但是即使选择要添加的表也不会添加表.

In a class library Ado.net Entity Data Model is has generated POCO classes. These were generated fine for the first time. But database changes are not being reflected. In edmx diagram right clicking and choosing Update Model from Database show newly created table but it do not add table even after selecting it to add.

我尝试运行.tt(通过右键单击并运行自定义工具),但即使它没有根据最新的数据库更改重新生成Poco类.

I tried running .tt (by right click and Run custom tool) but even it did not regenerated the Poco classes as per latest DB changes.

请帮助

推荐答案

不是解决方法,而是一种解决方法:简单地删除并重新生成EDMX和生成的类不是一种选择吗?这就是我的工作,它比使用更新功能要容易得多,并且结果似乎是相同的.您的POCO扩展程序仍保持不变并起作用.

Not a fix but a workaround: Is it not an option to simply remove and regenerate the EDMX and the generated classes? That's what I do, it is much easier than working with the update feature, and the result seems to be the same. Your POCO extensions still remain the same and functional.

我首先使用数据库,并且在源代码管理中拥有我的SQL升级脚本,生成的EDMX和生成的模型,并且那里的更改非常易于管理.这是每个版本的数据库升级过程的粗略概述:

I use database first and I have my SQL upgrade scripts, the generated EDMX and my Generated models in source control and the changes there are very easy to manage. Here is a rough outline of my DB upgrade process for each version:

  1. 创建用于升级的.sql脚本,例如CREATE TABLE等语句.
  2. 删除生成的文件:Model.Context.tt,Model.tt,Model.edmx
  3. 从Web.config中删除实体字符串(如果使用的话)
  4. 以与第一次相同的方式创建EDMX和Context文件
  5. 如果您使用源代码管理(希望您这样做!),请检查发生了什么变化
  6. 测试
  7. 提交!
  1. Create .sql script for the upgrade, statements like CREATE TABLE etc.
  2. Delete generated files: Model.Context.tt, Model.tt, Model.edmx
  3. Remove Entities string from Web.config (if you use it)
  4. Create the EDMX and Context files the same way you did for the first time
  5. If you use source control (I hope you do!) check what has changed
  6. Test
  7. Commit!

这篇关于EF Database首先如何为数据库更改更新模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆