Is there a way to make EF database first migration follow C# naming conventions? c# entity-framework-6


I'm developing a web application using ASP.Net MVC 5, and Entity Framework 6. I've performed a database first migration based off of the below database schema.

CREATE TABLE IF NOT EXISTS `database`.`table_name` (
    `some_value` INT NULL,
    `some_other_value` INT NULL,
    `some_other_ohter_value` INT NULL,
    PRIMARY KEY (`id`)

This results in the following class being generated:

public partial class table_name
    public int id { get; set; }
    public int some_value { get; set; }
    public int some_other_value { get; set; }
    public int some_other_ohter_value { get; set; }

Note that the class name, and properties directly match that of the table schema. Is there a way to have this class follow Pascal Case per C# naming conventions as per below?

public partial class TableName
    public int Id { get; set; }
    public int SomeValue { get; set; }
    public int SomeOtherValue { get; set; }
    public int SomeOtherOtherValue { get; set; }
2/15/2018 8:00:39 PM

Popular Answer

How did you do the database first migration?

If you generate a database from your schema and run this command (in the visual studio package manager console), I've found that the code generated follows C# standard naming conventions.

$tables = @('table_name')
Scaffold-DbContext $connstring Microsoft.EntityFrameworkCore.SqlServer -OutputDir 'DataAccess/Models' -Tables $tables -Force

You'll need the Microsoft.EntityFrameworkCore.Tools nuget package to access the Scaffold-DbContext cmdlet.


2/15/2018 8:05:10 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow