Entity Framework - only edmx without templates

2019-07-25 18:24发布

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.

3条回答
再贱就再见
2楼-- · 2019-07-25 18:59

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.

Custom Tool empty Final solution

查看更多
小情绪 Triste *
3楼-- · 2019-07-25 19:06

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. enter image description here

  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) enter image description here

  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.

enter image description here

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

查看更多
闹够了就滚
4楼-- · 2019-07-25 19:15

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.

enter image description here

Then I delete them and I update model from database:

enter image description here

and they don't come back:

they don't come back

This is from EF 6.2: enter image description here

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

查看更多
登录 后发表回答