Skip to content

Settings.PocoFolder

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

Settings.PocoFolder and the other folder settings

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.

They only work with separate files

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.

Example

Separate files, no folders

Category.cs
CategoryConfiguration.cs
IMyDbContext.cs
MyDbContext.cs
MyDbContextFactory.cs
Product.cs
ProductConfiguration.cs
sales_Order.cs
sales_OrderConfiguration.cs

With folders

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

Settings.UseFolderNameInNamespace

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.

When to use folders

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.

Gotchas

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.

See also

Clone this wiki locally