Skip to content

Settings.UseRegions

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

Settings.UseRegions

Wraps each section of a single-file generation in #region / #endregion so the file can be collapsed.

Type bool
Default true
Applies to EF 6 and EF Core
Databases All
In Database.tt? Yes

What it does

When everything lands in one file, that file is long. Regions let an editor collapse the parts you are not looking at, which is the difference between scrolling past two thousand lines and clicking past five headings.

Example

Settings.UseRegions = true (default)

#region Database context interface
#endregion
#region Database context
#endregion
#region Database context factory
#endregion
#region POCO classes
#endregion
#region POCO Configuration
#endregion

Settings.UseRegions = false

// No #region directives are written.

The code inside is identical either way; only the directives differ.

When to use it

Leave it true while Settings.GenerateSeparateFiles is false. That is the case regions exist for.

Turn it off when generating separate files. Each file then holds one class, so there is nothing to collapse and the directives are pure noise.

Turn it off if your team's style rules ban regions, which many do - the argument being that a file needing regions is a file that should have been split. That argument does not really apply to generated code you never edit, but consistency with a StyleCop or .editorconfig rule is a fair reason.

Gotchas

Regions only wrap the section groups, not individual classes. You get one region per kind of output - interface, context, factory, POCOs, configurations - not one per entity. Collapsing "POCO classes" collapses all of them at once.

No regions are written when generating separate files, whatever this is set to, because there is nothing to group.

It has no effect on the generated code's behaviour, and #region is invisible to the compiler. This is purely about reading the file.

See also

Clone this wiki locally