Skip to content

Settings.UsePascalCase

Simon Hughes edited this page Aug 30, 2026 · 1 revision

Settings.UsePascalCase

Turns database names into C# names - order_line_item becomes OrderLineItem - instead of using them exactly as the database spells them.

Type bool
Default true
Applies to EF 6 and EF Core
Databases All, and it matters most on PostgreSQL, MySQL and Oracle
In Database.tt? Yes

What it does

Database naming conventions are not C# naming conventions. snake_case is normal in PostgreSQL and MySQL, UPPER_SNAKE_CASE in Oracle, and neither belongs in a C# property name.

When this is true the generator splits names on underscores and spaces, capitalises each word, and joins them: order_line_item becomes OrderLineItem, qty_ordered becomes QtyOrdered. When it is false the database name is used verbatim.

The mapping back to the database is unaffected either way. HasColumnName always uses the real column name, so renaming is free.

Example

From a table deliberately named in snake_case:

CREATE TABLE dbo.order_line_item
(
    order_line_item_id int            NOT NULL IDENTITY(1, 1),
    unit_price         decimal(18, 2) NOT NULL,
    qty_ordered        int            NOT NULL,
    CONSTRAINT PK_order_line_item PRIMARY KEY (order_line_item_id)
);

Settings.UsePascalCase = true (default)

    // order_line_item
    public class OrderLineItem
    {
        public int OrderLineItemId { get; set; } // order_line_item_id (Primary key)
        public decimal UnitPrice { get; set; } // unit_price
        public int QtyOrdered { get; set; } // qty_ordered
    }

Settings.UsePascalCase = false

    // order_line_item
    public class order_line_item
    {
        public int order_line_item_id { get; set; } // order_line_item_id (Primary key)
        public decimal unit_price { get; set; } // unit_price
        public int qty_ordered { get; set; } // qty_ordered
    }

The comment after each property keeps the original database name either way, so you can always see where a property came from.

When to use it

Leave it true. It is the reason the generated code looks like C# rather than like a schema dump, and the comments mean you lose nothing.

Set it to false only when something downstream depends on the names matching the database exactly - a hand-written mapping layer, a serialiser configured by convention, or an existing codebase whose properties are already named the database way and which you cannot change.

If the problem is one table rather than the whole database, do not turn this off. Use Settings.TableRename or Settings.UpdateColumn to fix the one name.

Gotchas

Filters always match the database name, regardless of this setting. A RegexIncludeFilter("^OrderLineItem$") will never match order_line_item. See Filtering.

Turning it off does not disable pluralisation. The DbSet is still pluralised and the class name still singularised, so order_line_item gives you a class order_line_item and a DbSet called order_line_items. To stop that too, set Inflector.PluralisationService = null.

Oracle needs more than this. Oracle folds unquoted identifiers to upper case, so CATEGORIES PascalCases to CATEGORy - the singulariser strips the trailing S from an all-caps word. Lower-case it first in Settings.TableRename:

Settings.TableRename = (name, schema, isView) => Inflector.MakeLowerIfAllCaps(name);

See Oracle.

Enum members have their own setting. Settings.UsePascalCaseForEnumMembers controls those separately, so you can PascalCase your entities while leaving enum member names exactly as the data has them.

$ and spaces are stripped from names regardless of this setting, because neither is legal in a C# identifier.

See also

Clone this wiki locally