-
Notifications
You must be signed in to change notification settings - Fork 226
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 |
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.
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)
); // 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
} // 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.
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.
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.
- Settings.UsePascalCaseForEnumMembers
- Settings.TableRename | Settings.UpdateColumn - fixing individual names
- Filtering - which names filters see
- PostgreSQL | Oracle | MySQL - the case-folding rules per database
- Settings Reference
- Settings A-Z - every setting, with a page each
- Common Settings Types Explained
- Settings Callbacks
- Settings runtime values and helpers
- Filtering
- Full Control Over the Generated Code
- Enum Generation from Table Data
- Owned Entities
- JSON column support
- Global Query Filters
- Extended Property Names Feature
- Partial Properties
- File-Scoped Namespaces
- Data Annotations
- Spatial Types
- HierarchyId
- RowVersion and TimeStamp columns
- Lazy Loading
- Stored proc result sets
- Custom File-Based Templates
- Extra entities via partial classes
- INotifyPropertyChanged
- Syntax colour for T4