Skip to content

Settings.DisableGeographyTypes

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

Settings.DisableGeographyTypes and Settings.TrimCharFields

Two column-handling settings: one that skips spatial columns, one that trims the padding off fixed-length strings.

Settings.DisableGeographyTypes Settings.TrimCharFields
Type bool bool
Default true in Database.tt false
Applies to EF 6 and EF Core EF Core only
In Database.tt? Yes Yes

Settings.DisableGeographyTypes

Spatial types are off by default. The shipped Database.tt sets this true, even though the Settings class field initialiser says false - and the .tt is what runs. If you have never touched it, spatial columns are being skipped.

Turn it off to generate them:

Settings.DisableGeographyTypes = false;

Spatial support needs a package and a provider call your project must supply, which is why it is opt-in:

Install-Package Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite
optionsBuilder.UseSqlServer(connectionString, x => x.UseNetTopologySuite());

What a spatial column maps to depends on the database - NetTopologySuite types on SQL Server and MySQL, PostgisGeometry on PostgreSQL, nothing usable on Oracle. See Spatial Types.

Leave it true for OData, which cannot serialise entities containing geometry or geography types. That is the original reason the setting exists.

A stored procedure with a spatial parameter or a spatial column in its return model is not generated at all while this is true. If a procedure has silently gone missing, this is the first thing to check.

Settings.TrimCharFields

char(10) is fixed length: store "AB" and read back "AB ". That is the database being correct and your code almost never wanting it.

With this on, EF Core is told to TrimEnd() the value as it materialises, so you get "AB".

Settings.TrimCharFields = true;

Turn it on if you have char or nchar columns and are tired of .Trim() at every comparison. Leave it off if the padding is meaningful - it occasionally is, in fixed-format interchange data.

Gotchas

DisableGeographyTypes defaults differently from what you might read elsewhere. true in the .tt, false in the class. The .tt wins.

TrimCharFields is EF Core only. On EF 6 it is read and ignored.

TrimCharFields trims on read, not on write. Save "AB" into a char(10) and the database still pads it. The round trip is therefore not symmetrical, and a WHERE clause comparing against the untrimmed value still needs the padding - or LIKE.

It applies to every char column, with no per-column control. For one column, override it in Settings.UpdateColumn instead.

varchar is unaffected by TrimCharFields, because it is not padded in the first place.

See also

Clone this wiki locally