-
Notifications
You must be signed in to change notification settings - Fork 226
Settings.PocoFolder
Where each kind of generated file is written, once you are generating separate files.
| Setting | Default in Database.tt
|
Holds |
Settings.ContextFolder |
@"" |
The DbContext and its factory |
Settings.InterfaceFolder |
@"Interface" |
The context interface |
Settings.PocoFolder |
@"Entities" |
The entity classes |
Settings.PocoConfigurationFolder |
@"Configuration" |
The Fluent API configuration classes |
Settings.OwnedEntityFolder |
"" |
Owned entity classes; falls back to PocoFolder
|
Settings.UseFolderNameInNamespace |
false |
Whether the namespace follows the folder |
All are string, all are relative to the folder holding your .tt file, and all apply to EF 6 and EF Core on
every database.
The shipped Database.tt assigns the first five inside a conditional, and that is not an accident:
if (Settings.GenerateSeparateFiles)
{
Settings.ContextFolder = @"";
Settings.InterfaceFolder = @"Interface";
Settings.PocoFolder = @"Entities";
Settings.PocoConfigurationFolder = @"Configuration";
Settings.UseFolderNameInNamespace = false;
}With Settings.GenerateSeparateFiles off there is one output file, it goes
next to the .tt, and these settings are never read. If you set a folder and nothing moved, that is why.
Category.cs
CategoryConfiguration.cs
IMyDbContext.cs
MyDbContext.cs
MyDbContextFactory.cs
Product.cs
ProductConfiguration.cs
sales_Order.cs
sales_OrderConfiguration.cs
Settings.ContextFolder = @"Data";
Settings.InterfaceFolder = @"Data\Interface";
Settings.PocoFolder = @"Data\Entities";
Settings.PocoConfigurationFolder = @"Data\Configuration";Data/Configuration/CategoryConfiguration.cs
Data/Configuration/ProductConfiguration.cs
Data/Configuration/sales_OrderConfiguration.cs
Data/Entities/Category.cs
Data/Entities/Product.cs
Data/Entities/sales_Order.cs
Data/Interface/IMyDbContext.cs
Data/MyDbContext.cs
Data/MyDbContextFactory.cs
By default the folders are a filing decision only - every class stays in
Settings.Namespace regardless of which folder it landed in. That is
unusual for a .NET project, where folder and namespace normally match.
Turn this on and they do match: PocoFolder = "Entities" puts the entities in MyApp.Data.Entities.
Turn it on if your team's convention or an analyser expects folder and namespace to agree. Leave it off if you
would rather one flat namespace, which means consumers need one using rather than four.
Any model beyond a handful of tables. Sixty files in one folder next to the .tt is not a structure.
Matching an existing project layout, so generated entities sit where hand-written ones already do.
Changing a folder leaves the old files behind. The generator's audit file tracks what it wrote and deletes
files it no longer generates - but only within the folders it knows about. Move PocoFolder and the previous
folder's contents are orphaned, and they still compile, so you get duplicate type errors. Delete the old
folder by hand.
Use @"..." or double the backslashes. These are Windows paths in C# string literals. "Data\Entities"
contains an escape sequence; @"Data\Entities" is what you want. Forward slashes also work.
Old-style projects do not pick up new files. A non-SDK .csproj that lists every file with
<Compile Include="..." /> needs the new files adding by hand. SDK-style projects glob and need nothing.
OwnedEntityFolder falls back to PocoFolder, not to the root, when left empty.
Absolute paths are not supported. These are relative to Settings.Root.
- Settings.GenerateSeparateFiles - the switch that makes these do anything
- Settings.Namespace and the cross-namespace settings
- Settings.ElementsToGenerate - splitting across projects rather than folders
- Owned Entities
- 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