Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T4 template to exclude from the generated code database artifacts not used by EF Core at runtime #10890

Open
Tracked by #22948
bricelam opened this issue Feb 6, 2018 · 11 comments

Comments

@bricelam
Copy link
Contributor

bricelam commented Feb 6, 2018

The following are currently unused by the runtime (outside of Migrations) and can be safely removed from the scaffolded code:

  • Sequences
  • Constraint names
  • Non-unique indexes
  • Index filters
@bricelam
Copy link
Contributor Author

bricelam commented Feb 6, 2018

Update from Database may benefit from having the constraint names.

@ErikEJ
Copy link
Contributor

ErikEJ commented Feb 6, 2018

Great info, thanks Brice

@roji
Copy link
Member

roji commented Jul 31, 2018

See #12837 (comment) for some possible reservations...

Out of curiosity, have people actually been complaining about this? Is it really that hard to just remove the unwanted stuff from your model manually? I guess I put a high bar on extra command-line switches...

@ajcvickers
Copy link
Member

@roji Not disagreeing with you, but two things play the other way:

  • Large models, with 1000's of tables. This makes both the extra overhead more significant, and makes the guidance to make 1000's of edits somewhat unpalatable. We haven't had issues related to this specifically for large models, but several people have run into related issues.
  • Since there is no "update from database" our current guidance for a "database first" type flow is to re-generate the model when the database has changed. Adding in a bunch of manual edits as well makes this guidance even more unpalatable than it already is.

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 31, 2018

Adding in a bunch of manual edits as well makes this guidance even more unpalatable than it already is.

I use that workflow in production and it is actually not so bad...

@ajcvickers
Copy link
Member

@ErikEJ Good to hear! Including the manual edits? How much manual editing do you do, and how often does the database need to be re-scaffolded?

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 31, 2018

We dont do any manual edits.

We use partial DbContext and Entity Classes, and each developer re-scaffolds on each schema change (we use SSDT project for the schema, so generate directly from the dacpac via EFPT, but might as well be from a local scratch database)

@sbrockway
Copy link

My comment on the docs page got merged into this issue.
From my perspective the constraint name is not necessary for the mapping. In fact, correct me if I'm wrong: I would assume that having the constraint name mapped would break the mapping if someone were to change the constraint name on the SQL side.
Why couple to the name by default? I would like to see the default omit anything that isn't necessary for the mapping, with an opt in for the extra bits for those that need/want it.

@bricelam
Copy link
Contributor Author

bricelam commented Feb 5, 2020

I put together a sample in bricelam/EFCore.TextTemplating showing how to use T4 templates to customize the code scaffolded by Scaffold-DbContext (and dotnet ef dbcontext scaffold). The default templates I provided only scaffold the things required to make EF Core work. Check it out if you're interested.

@oliverkane
Copy link

@bricelam, I took a look at your project for templating and it seems like just what the doctor ordered. A whole lot to learn, since I've never used the T4 templates, but seems like a great time to learn. Thanks for putting that together!

@ajcvickers
Copy link
Member

Note: this will be possible once #4038 is implemented, which is planned for 7.0, and is already possible with the Power Tools.

@ajcvickers ajcvickers changed the title RevEng: Option to omit artifacts unused by the runtime T4 template to exclude from the generated code database artifacts not used by EF Core at runtime Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants