Skip to content

what is the best way to add our own namespace while generating the model via Scaffolding  #30332

@archanasoni

Description

@archanasoni

Hi,

We've requierment to add using statement :
using IBM.EntityFrameworkCore

Above statement has to be added while generating the Context class via scaffolding. Till .NET 6 we implemented CSharpDbContextGenerator and added in our service, but from .NET7 we see it is part of .tt file which we are not much familior..
how can we achieve the same result now ?

public override string WriteCode(
                    IModel model,
                    string contextName,
                    string connectionString,
                    string? contextNamespace,
                    string? modelNamespace,
                    bool useDataAnnotations,
                    bool useNullableReferenceTypes,                   
                    bool suppressConnectionStringWarning,
         bool suppressOnConfiguring)
        {
            Check.NotNull(model, nameof(model));
#pragma warning disable EF1001 // Internal EF Core API usage.
            _sb = new IndentedStringBuilder();
            _sb.AppendLine("using IBM.EntityFrameworkCore;");
            //_sb.AppendLine("using IBM.EntityFrameworkCore.Storage.Internal;");
            return _sb.AppendLines(base.WriteCode(model, contextName, connectionString, contextNamespace, modelNamespace, useDataAnnotations, useNullableReferenceTypes, suppressConnectionStringWarning, suppressOnConfiguring)).ToString();
#pragma warning restore EF1001 // Internal EF Core API usage.
        }

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions