Search Results for

    Show / Hide Table of Contents

    Interface INpgsqlTypeMapper

    A type mapper, managing how to read and write CLR values to PostgreSQL data types. A type mapper exists for each connection, as well as a single global type mapper (accessible via NpgsqlConnection.GlobalTypeMapper).

    Namespace: Npgsql.TypeMapping
    Assembly: Npgsql.dll
    Syntax
    public interface INpgsqlTypeMapper

    Properties

    DefaultNameTranslator

    The default name translator to convert CLR type names and member names.

    Declaration
    INpgsqlNameTranslator DefaultNameTranslator { get; }
    Property Value
    Type Description
    INpgsqlNameTranslator

    Mappings

    Enumerates all mappings currently set up on this type mapper.

    Declaration
    IEnumerable<NpgsqlTypeMapping> Mappings { get; }
    Property Value
    Type Description
    IEnumerable<NpgsqlTypeMapping>

    Methods

    AddMapping(NpgsqlTypeMapping)

    Adds a new type mapping to this mapper, overwriting any existing mapping in the process.

    Declaration
    INpgsqlTypeMapper AddMapping(NpgsqlTypeMapping mapping)
    Parameters
    Type Name Description
    NpgsqlTypeMapping mapping
    Returns
    Type Description
    INpgsqlTypeMapper

    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 enum type in the database. If null, the name translator given in nameTranslatorwill be used.

    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
    INpgsqlTypeMapper
    Type Parameters
    Name Description
    T

    The .NET type to be mapped

    Remarks

    CLR fields and properties by string 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 members to manually specify a PostgreSQL enum label. If there is a discrepancy between the .NET and database labels 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 nameTranslatorwill be used.

    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
    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.

    RemoveMapping(String)

    Removes an existing mapping from this mapper. Attempts to read or write this type after removal will result in an exception.

    Declaration
    bool RemoveMapping(string pgTypeName)
    Parameters
    Type Name Description
    String pgTypeName

    A PostgreSQL type name for the type in the database.

    Returns
    Type Description
    Boolean

    Reset()

    Resets all mapping changes performed on this type mapper and reverts it to its original, starting state.

    Declaration
    void Reset()

    UnmapComposite<T>(String, INpgsqlNameTranslator)

    Removes an existing enum 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 nameTranslatorwill be used.

    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
    Boolean
    Type Parameters
    Name Description
    T

    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 nameTranslator will be used.

    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
    Boolean
    Type Parameters
    Name Description
    TEnum

    Extension Methods

    NpgsqlJsonNetExtensions.UseJsonNet(INpgsqlTypeMapper, Type[], Type[], Nullable<JsonSerializerSettings>)
    NpgsqlRawPostgisExtensions.UseRawPostgis(INpgsqlTypeMapper)
    NpgsqlGeoJSONExtensions.UseGeoJson(INpgsqlTypeMapper, GeoJSONOptions, Boolean)
    NpgsqlLegacyPostgisExtensions.UseLegacyPostgis(INpgsqlTypeMapper)
    NpgsqlNetTopologySuiteExtensions.UseNetTopologySuite(INpgsqlTypeMapper, Nullable<CoordinateSequenceFactory>, Nullable<PrecisionModel>, Ordinates, Boolean)
    NpgsqlNodaTimeExtensions.UseNodaTime(INpgsqlTypeMapper)
    In This Article
    Back to top © Copyright 2022 The Npgsql Development Team