问题
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:
- Add the Entity Data Model (EF Designer from database)
- Cancel initial execution of the tools
- Empty
Custom Toolvalue on each.ttfile and on the.edmxfile - Delete contents of the
.ttfiles if you want - Delete
.diagramfile
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.
- Delete
.ttfiles under your.edmxfile. - Project -> Add -> New Item ->
EF 6.x DbContext Generator It will generate new
.ttfiles. In these.ttfiles you can specify.edmxfile path.Run these
.ttfiles to generateModel1classes.Disable
.ttfiles (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)Update your
.edmx(add/remove tables).- This will not generate new
.ttfiles under edmx - And it will not update your entity classes.
- And if you want to update your entity classes, then run
.ttfiles.
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