Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

renaming entities while scaffolding in EF Core 6 #28329

Closed
kedarrkulkarni opened this issue Jun 27, 2022 · 2 comments
Closed

renaming entities while scaffolding in EF Core 6 #28329

kedarrkulkarni opened this issue Jun 27, 2022 · 2 comments

Comments

@kedarrkulkarni
Copy link

*This might be a feature request and not support query, hence posting here

Looking for a suggestion about database first, Scaffold-Dbcontext utility in EF Core 6
All our database tables start with fixed prefix that I am keen to remove while entities are generated by scaffold I am looking to

I have previously handled similar requirement using code similar to the one below, with EF Core 3.0

using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore.Scaffolding.Internal;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;

namespace ProjectName.Entity.Models
{
    public class ProjectNameEntityTypeGenerator : CSharpUtilities
    {
        public override string Uniquifier(string proposedIdentifier, ICollection<string> existingIdentifiers)
        {
            var finalIdentifier = base.Uniquifier(proposedIdentifier, existingIdentifiers);

            //Prefix entity names with underscore
            if (finalIdentifier.ToLower().StartsWith("tbl"))
            {
                finalIdentifier = finalIdentifier.Replace("Tbl", string.Empty);
            }

            return finalIdentifier;
        }
    }

    public class CustomEFDesignTimeServices : IDesignTimeServices
    {
        //Used for scaffolding database to code
        public void ConfigureDesignTimeServices(IServiceCollection serviceCollection)
        {
            serviceCollection.AddSingleton<ICSharpUtilities, ProjectNameEntityTypeGenerator>();
        }
    }
}

However, EF Core has completely changed the namespace/class structure and CSharpUtilities class is no longer available.

What is the alternate option available in EF Core 6 to control naming of the entities as part of entity generation? we certainly don't want to manually rename the entity names after generation as it's not very productive and also because we want to add more options over naming of auto generated entities.

Include provider and version information

EF Core version: 6
Database provider: (e.g. Oracle.EntityFrameworkCore)
Target framework: (e.g. .NET 6.0)
Operating system:
IDE: (e.g. Visual Studio 2022)

@ErikEJ
Copy link
Contributor

ErikEJ commented Jun 27, 2022

You can do regex based renaming with EF Core Power Tools.

@AndriySvyryd
Copy link
Member

This will be supported in 7.0 with #4038

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants