从数据库实体框架更新模型在TT类不产生CS类新增加的表 [英] Entity framework update model from database not generating cs class for newly added table in tt class

查看:1837
本文介绍了从数据库实体框架更新模型在TT类不产生CS类新增加的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用实体框架5与Visual Studio 2012

I am using entity framework 5 with visual studio 2012.

我有一个现有的模型。现在我想一个新的表添加到现有的模型。对于我已经打开了edxm文件,并使用鼠标右键我成功更新模型。

I do have an existing model. Now I want to add a new table to that existing model. For that I have opened the edxm file and using right click I updated the model successfully.

现在,在模型浏览器下的EntityTypes的模式,我可以看到表名称存在。但是,在Solution Explorer中未显示,因为我已经.TT文件下新增的表自动生成cs文件。

Now, in "Model Browser" under "EntityTypes" for model, I can see the table name exists. But in Solution Explorer it is not showing the auto-generated .cs file for the table I have added newly under .tt file.

我试过运行自定义工具,但它并没有生成的类。同时也有重新启动的Visual Studio,但结果是一样的。

I tried "run custom tool" but it has not generated the class. Also have restarted the Visual Studio but result is the same.

谁能帮我?

感谢

推荐答案

问题


  1. 在情况下,你的数据库中,但之后加入实体数据模型你变了实体有表名 tblEmployee tblEmployee 员工在EDMX文件,然后保存并生成。但是,对于更名的类不Model1.tt文件自动生成。

  2. 更新模型从数据库添加新表同样的问题发生。

  3. 此外,在MVC不可用在创建视图与模型类/创建控制器,使用的EntityFramework操作

  1. In case you have table name tblEmployee in Database But after the adding 'Entity Data Model' you have Changed Entity tblEmployee to Employee in EDMX file then Save and Build. But Classes for Changed Name are not Generated Automatically in Model1.tt file.
  2. When "Update Model From Database" for adding new table same Problem occurs.
  3. Also not available in MVC When creating view with Model Class/Create Controller With Actions using EntityFramework

这问题是VS2012.This问题早期版本解决了VS2012的升级版本。

This problem is for early version of VS2012.This problem is solved in upgraded version of VS2012.

解决方案

我们有VS2012和放大器的早期版本,该解决方案; EF 5.0

we have solution for this with early version of VS2012 & EF 5.0

按照步骤


  1. 右键单击在Model1.tt并选择运行自定义工具保存和现在建立看到生成的类。

  2. 右键单击Model1.Context.tt并选择运行自定义工具保存和现在建立看到的是像

  1. Right click On Model1.tt and select 'Run Custom Tool' save and Build Now see classes are generated.
  2. Right click On Model1.Context.tt and select 'Run Custom Tool' save and Build Now see property IN Context class is generated like

public DbSet<Employee> Employees { get; set; } 


保存并生成解决方案

Model1Context context=new Model1Context();
List<Employee> empList= context.Employees.ToList();

这为我工作。
但是,请记住,还是EF 6.0无法在MVC这个viersion VS2012的'使用的EntityFramework创建控制器和视图时做脚手架。
您必须使用EF 5.0或更新VS2012与新的更新。

This worked for me. But Keep in mind that still EF 6.0 not able to make Scaffolding when 'creating controller and view using entityframework' in MVC with this viersion of VS2012. You must Use EF 5.0 or update VS2012 with new update.

这篇关于从数据库实体框架更新模型在TT类不产生CS类新增加的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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