Entity Framework - only edmx without templates

自作多情 提交于 2019-12-11 06:51:08

问题


We would like to add only .EDMX files without corresponding .tt files for context and entities. There is multiple reasons for this, but long story short - we would like to be able to have .EDMX and be able to refresh it from DB when needed.

Currently if I delete .tt files every time I "Update from DB" it will regenerate .tt files and entitites which we don't need.


回答1:


If it's enough to have only the .edmx with two empty .tt files you can do that:

  1. Add the Entity Data Model (EF Designer from database)
  2. Cancel initial execution of the tools
  3. Empty Custom Tool value on each .tt file and on the .edmx file
  4. Delete contents of the .tt files if you want
  5. Delete .diagram file

After this steps, you can update your .edmx file and nothing happens.




回答2:


I'm not sure I understand fully, but I simply delete the pair of t4/tt files that are included with the model and the previously generated class files. They don't come back for EF6.

Then I delete them and I update model from database:

and they don't come back:

This is from EF 6.2:

Are you sure you're not dealing with some source control issue?




回答3:


You can try this.

  1. Delete .tt files under your .edmx file.
  2. Project -> Add -> New Item -> EF 6.x DbContext Generator
  3. It will generate new .tt files. In these .tt files you can specify .edmx file path.

  4. Run these .tt files to generate Model1 classes.

  5. Disable .tt files (Don't delete content as you will need it if you want to update your entities later. Usually they generate new files when you save them)

  6. Update your .edmx (add/remove tables).

  7. This will not generate new .tt files under edmx
  8. And it will not update your entity classes.
  9. And if you want to update your entity classes, then run .tt files.

I tried this and "Update Model From Database" didn't generate new .tt files. So hopefully your problem will be solved.



来源:https://stackoverflow.com/questions/55288485/entity-framework-only-edmx-without-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!