R4ND3LL / EntityFrameworkRuler

Provides a reasonable way to do DB-first development with EF Core by allowing the customization of the reverse engineered model (i.e. scaffolding), including EDMX support for EF6 upgrades.
MIT License
21 stars 6 forks source link

How to run additional code generation? #24

Closed MagicAndre1981 closed 1 year ago

MagicAndre1981 commented 1 year ago

In old EF6 with EDMX I used a T4 script to also generate additional .cs file per entity where I generate overrides for Equals, ==, != ,ToString, GetHashCode otherwise Checks failed for EF6 because of the proxy generation.

Is this still an issue with EF Core and how can I also generate such addition code into additional partial class .cs files when I run the Scaffold-DbContext command?

R4ND3LL commented 1 year ago

EF Core 7 has full t4 support: https://learn.microsoft.com/en-us/ef/core/managing-schemas/scaffolding/templates?tabs=dotnet-core-cli

You can look at the test project in the EFR repo for an example: https://github.com/R4ND3LL/EntityFrameworkRuler/tree/main/src/Tests/NorthwindTestDesign/CodeTemplates/EFCore

Also, note, EFR provides an additional feature that allows each entity configuration to be split into its own file rather than all configurations being in one file. You can opt into this feature by setting this property at the json root level: "SplitEntityTypeConfigurations": true,

MagicAndre1981 commented 1 year ago

ok, so I have to wait for a EF Core 7 compatible Firebird provider version.

R4ND3LL commented 1 year ago

that would be correct, as far as I know. EFR could potentially provide the T4 capability to EF Core 6 by running the same templating code as EF7. The code for doing that is not that serious. However that hasn't been on my radar so far since most would just use EF7

R4ND3LL commented 1 year ago

just a note. since I would consider this item "unplanned" since most can just use EF7 now, I would be open to treating it as commission basis if it's important to you (adding t4 support to v6). perhaps via github sponsorship. entirely up to you. just wanted to provide the option.