user917170 user917170 - 1 year ago 192
C# Question

Entity Framework Core - Customise Scaffolding

In Entity Framework 6 we can add the T4 templates the scaffolding uses by running

Install-Package EntityFramework.CodeTemplates.CSharp

But in Entity Framework Core the scaffolding system does not appear to use T4 templates, nor does it seem like the scaffolding can be customised. It seems to be all in c# classes eg.

Is there any way to customise the output from the scaffold?

Answer Source

There is a special, yet-to-be-documented hook to override design-time services:

class Startup // Can also be in Program or App
    public static void ConfigureDesignTimeServices(IServiceCollection services)
        => services.AddSingleton<EntityTypeWriter, MyEntityTypeWriter>();

Then implement your custom generator.

class MyEntityTypeWriter : EntityTypeWriter
    public EntityTypeWriter(CSharpUtilities cSharpUtilities)
        : base(cSharpUtilities)

    // TODO: Override with custom implementation
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download