EF Core Power Tools database reverse engineering: renaming of entities and properties
Entity Framework Core Power Tools (my free, open source Visual Studio extension, that helps you be more productive with EF Core), includes a feature to rename entities and properties.
This can be useful in several cases, for example if you have "legacy" table and columns names in your database, and would like to be able to use more readable names in your code.
The implementation of this feature required changes to EF Core, but thanks to the open nature of the EF Core project, I got a PR accepted to enable exactly that feature.
The feature was implemented with great help from GitHub user tomzre as you can see here.
Using the renaming feature
To implement renaming of entities and properties, add a .json file named efpt.renaming.json at the root of your project.
Given the following schema:
CREATE TABLE dbo.course_sched
(
ident INT PRIMARY KEY NOT NULL,
subj_area_cd VARCHAR(30) NOT NULL
)
the efpt.renaming.json sample file below will generate these names in the model:
public virtual DbSet<CourseOffering> CourseOffering { get; set; }
and CourseOffering.cs with SubjectArea and Id string properties.
[
{
"UseSchemaName": false,
"SchemaName": "dbo",
"Tables": [
{
"Name": "course_sched",
"NewName": "CourseOffering",
"Columns": [
{
"Name": "subj_area_cd",
"NewName": "SubjectArea"
},
{
"Name": "identifier",
"NewName": "Id"
}
]
}
]
}
]
You can also use this to have custom naming of tables with same name in different schemas, as in this example.
In order to do mass re-namings, you can create your own to to populate a class like this one, and the write it to a .json file with code like this:
File.WriteAllText("efpt.renaming.json", JsonConvert.SerializeObject(schemas), Encoding.UTF8);
If you manage to create a nice, general purpose tool (maybe simply a command line tool), I will be very happy to receive a PR :-)