-
Notifications
You must be signed in to change notification settings - Fork 226
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 |
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.
#region Database context interface
#endregion
#region Database context
#endregion
#region Database context factory
#endregion
#region POCO classes
#endregion
#region POCO Configuration
#endregion
// No #region directives are written.
The code inside is identical either way; only the directives differ.
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.
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.
- Settings.GenerateSeparateFiles - the setting that makes regions unnecessary
- Settings.UsePragma | Settings.UseResharper - the other two "what goes at the top of the file" settings
- 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