Skip to content

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

Description

@bricelam

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

Activity

  1. bricelam commented on Feb 6, 2018

    @bricelam
    ContributorAuthor

    Update from Database may benefit from having the constraint names.

  2. ErikEJ commented on Feb 6, 2018

    @ErikEJ
    Contributor

    Great info, thanks Brice

  3. added this to the Backlog milestone on Feb 7, 2018
  4. roji commented on Jul 31, 2018

    @roji
    Member

    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...

  5. ajcvickers commented on Jul 31, 2018

    @ajcvickers
    Contributor

    @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.
  6. ErikEJ commented on Jul 31, 2018

    @ErikEJ
    Contributor

    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...

  7. ajcvickers commented on Jul 31, 2018

    @ajcvickers
    Contributor

    @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?

  8. ErikEJ commented on Jul 31, 2018

    @ErikEJ
    Contributor

    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)

  9. sbrockway commented on Nov 15, 2019

    @sbrockway

    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.

  10. bricelam commented on Feb 5, 2020

    @bricelam
    ContributorAuthor

    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.

  11. oliverkane commented on Feb 22, 2020

    @oliverkane

    @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!

  12. modified the milestone: Backlog on Nov 8, 2021
  13. ajcvickers commented on Nov 10, 2021

    @ajcvickers
    Contributor

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

  14. 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[/+] on Oct 26, 2022
  15. added theissue type on Jun 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions