-
Notifications
You must be signed in to change notification settings - Fork 226
Settings.DisableGeographyTypes
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 |
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.
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.
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.
- Spatial Types - the per-database mapping table and the setup
- Settings.UpdateColumn - per-column overrides for either
- Settings.DatabaseType
- 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