Interface INpgsqlTypeMapper
A type mapper, managing how to read and write CLR values to PostgreSQL data types.
Namespace: Npgsql.TypeMapping
Assembly: Npgsql.dll
Syntax
public interface INpgsqlTypeMapper
Remarks
The preferred way to manage type mappings is on NpgsqlDataSourceBuilder. An alternative, but discouraged, method, is to manage them globally via GlobalTypeMapper).
Properties
| Improve this Doc View SourceDefaultNameTranslator
The default name translator to convert CLR type names and member names. Defaults to NpgsqlSnakeCaseNameTranslator.
Declaration
INpgsqlNameTranslator DefaultNameTranslator { get; set; }
Property Value
Type | Description |
---|---|
INpgsqlNameTranslator |
Remarks
The preferred way to manage type mappings is on NpgsqlDataSourceBuilder. An alternative, but discouraged, method, is to manage them globally via GlobalTypeMapper).
Methods
| Improve this Doc View SourceAddTypeInfoResolver(IPgTypeInfoResolver)
Adds a type info resolver which can add or modify support for PostgreSQL types. Typically used by plugins.
Declaration
void AddTypeInfoResolver(IPgTypeInfoResolver resolver)
Parameters
Type | Name | Description |
---|---|---|
IPgTypeInfoResolver | resolver | The type resolver to be added. |
Remarks
The preferred way to manage type mappings is on NpgsqlDataSourceBuilder. An alternative, but discouraged, method, is to manage them globally via GlobalTypeMapper).
MapComposite(Type, string?, INpgsqlNameTranslator?)
Maps a CLR type to a composite type.
Declaration
INpgsqlTypeMapper MapComposite(Type clrType, string? pgName = null, INpgsqlNameTranslator? nameTranslator = null)
Parameters
Type | Name | Description |
---|---|---|
Type | clrType | The .NET type to be mapped. |
string? | pgName | A PostgreSQL type name for the corresponding composite type in the database.
If null, the name translator given in |
INpgsqlNameTranslator | nameTranslator | A component which will be used to translate CLR names (e.g. SomeClass) into database names (e.g. some_class). Defaults to DefaultNameTranslator. |
Returns
Type | Description |
---|---|
INpgsqlTypeMapper |
Remarks
Maps CLR fields and properties by string to PostgreSQL names.
The translation strategy can be controlled by the nameTranslator
parameter,
which defaults to DefaultNameTranslator.
If there is a discrepancy between the .NET type and database type while a composite is read or written,
an exception will be raised.
MapComposite<T>(string?, INpgsqlNameTranslator?)
Maps a CLR type to a PostgreSQL composite type.
Declaration
INpgsqlTypeMapper MapComposite<T>(string? pgName = null, INpgsqlNameTranslator? nameTranslator = null)
Parameters
Type | Name | Description |
---|---|---|
string? | pgName | A PostgreSQL type name for the corresponding composite type in the database.
If null, the name translator given in |
INpgsqlNameTranslator | nameTranslator | A component which will be used to translate CLR names (e.g. SomeClass) into database names (e.g. some_class). Defaults to DefaultNameTranslator. |
Returns
Type | Description |
---|---|
INpgsqlTypeMapper |
Type Parameters
Name | Description |
---|---|
T | The .NET type to be mapped |
Remarks
CLR fields and properties by string to PostgreSQL names.
The translation strategy can be controlled by the nameTranslator
parameter,
which defaults to NpgsqlSnakeCaseNameTranslator.
You can also use the PgNameAttribute on your members to manually specify a PostgreSQL name.
If there is a discrepancy between the .NET type and database type while a composite is read or written,
an exception will be raised.
MapEnum<TEnum>(string?, INpgsqlNameTranslator?)
Maps a CLR enum to a PostgreSQL enum type.
Declaration
INpgsqlTypeMapper MapEnum<TEnum>(string? pgName = null, INpgsqlNameTranslator? nameTranslator = null) where TEnum : struct, Enum
Parameters
Type | Name | Description |
---|---|---|
string? | pgName | A PostgreSQL type name for the corresponding enum type in the database.
If null, the name translator given in |
INpgsqlNameTranslator | nameTranslator | A component which will be used to translate CLR names (e.g. SomeClass) into database names (e.g. some_class). Defaults to DefaultNameTranslator. |
Returns
Type | Description |
---|---|
INpgsqlTypeMapper |
Type Parameters
Name | Description |
---|---|
TEnum | The .NET enum type to be mapped |
Remarks
CLR enum labels are mapped by name to PostgreSQL enum labels.
The translation strategy can be controlled by the nameTranslator
parameter,
which defaults to NpgsqlSnakeCaseNameTranslator.
You can also use the PgNameAttribute on your enum fields to manually specify a PostgreSQL enum label.
If there is a discrepancy between the .NET and database labels while an enum is read or written,
an exception will be raised.
Reset()
Resets all mapping changes performed on this type mapper and reverts it to its original, starting state.
Declaration
void Reset()
Remarks
The preferred way to manage type mappings is on NpgsqlDataSourceBuilder. An alternative, but discouraged, method, is to manage them globally via GlobalTypeMapper).
UnmapComposite(Type, string?, INpgsqlNameTranslator?)
Removes an existing composite mapping.
Declaration
bool UnmapComposite(Type clrType, string? pgName = null, INpgsqlNameTranslator? nameTranslator = null)
Parameters
Type | Name | Description |
---|---|---|
Type | clrType | The .NET type to be unmapped. |
string? | pgName | A PostgreSQL type name for the corresponding composite type in the database.
If null, the name translator given in |
INpgsqlNameTranslator | nameTranslator | A component which will be used to translate CLR names (e.g. SomeClass) into database names (e.g. some_class). Defaults to DefaultNameTranslator. |
Returns
Type | Description |
---|---|
bool |
Remarks
The preferred way to manage type mappings is on NpgsqlDataSourceBuilder. An alternative, but discouraged, method, is to manage them globally via GlobalTypeMapper).
UnmapComposite<T>(string?, INpgsqlNameTranslator?)
Removes an existing composite mapping.
Declaration
bool UnmapComposite<T>(string? pgName = null, INpgsqlNameTranslator? nameTranslator = null)
Parameters
Type | Name | Description |
---|---|---|
string? | pgName | A PostgreSQL type name for the corresponding composite type in the database.
If null, the name translator given in |
INpgsqlNameTranslator | nameTranslator | A component which will be used to translate CLR names (e.g. SomeClass) into database names (e.g. some_class). Defaults to NpgsqlSnakeCaseNameTranslator |
Returns
Type | Description |
---|---|
bool |
Type Parameters
Name | Description |
---|---|
T |
Remarks
The preferred way to manage type mappings is on NpgsqlDataSourceBuilder. An alternative, but discouraged, method, is to manage them globally via GlobalTypeMapper).
UnmapEnum<TEnum>(string?, INpgsqlNameTranslator?)
Removes an existing enum mapping.
Declaration
bool UnmapEnum<TEnum>(string? pgName = null, INpgsqlNameTranslator? nameTranslator = null) where TEnum : struct, Enum
Parameters
Type | Name | Description |
---|---|---|
string? | pgName | A PostgreSQL type name for the corresponding enum type in the database.
If null, the name translator given in |
INpgsqlNameTranslator | nameTranslator | A component which will be used to translate CLR names (e.g. SomeClass) into database names (e.g. some_class). Defaults to DefaultNameTranslator. |
Returns
Type | Description |
---|---|
bool |
Type Parameters
Name | Description |
---|---|
TEnum |
Remarks
The preferred way to manage type mappings is on NpgsqlDataSourceBuilder. An alternative, but discouraged, method, is to manage them globally via GlobalTypeMapper).