本文介绍了实体框架核心-自定义脚手架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Entity Framework 6中,我们可以通过运行来添加脚手架使用的T4模板

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

Install-Package EntityFramework.CodeTemplates.CSharp

但是在Entity Framework Core中,脚手架系统似乎没有使用T4模板,看起来也不像可以定制脚手架。它似乎全部在c#类中。

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?

推荐答案

有是一个特殊的,尚待记录的钩子,用于覆盖设计时服务:

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

class Startup
{
    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
}

更新:请参见的答案,以了解另一种方法EF Core 1.0.2 +。

Update: See Yehuda Goldenberg's answer for another way to do this in EF Core 1.0.2+.

这篇关于实体框架核心-自定义脚手架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 03:33