# Class NpgsqlModelBuilderExtensions

Namespace
  Microsoft.EntityFrameworkCore

Assembly
  Npgsql.EntityFrameworkCore.PostgreSQL.dll

Npgsql-specific extension methods for ModelBuilder.

    public static class NpgsqlModelBuilderExtensions

Inheritance
  object
  NpgsqlModelBuilderExtensions

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

## Methods

### CanSetHiLoSequence(IConventionModelBuilder, string?, string?, bool)

Returns a value indicating whether the given name and schema can be set for the hi-lo sequence.

    public static bool CanSetHiLoSequence(this IConventionModelBuilder modelBuilder, string? name, string? schema, bool fromDataAnnotation = false)

#### Parameters

`modelBuilder` IConventionModelBuilder

  The model builder.

`name` string

  The name of the sequence.

`schema` string

  The schema of the sequence.

`fromDataAnnotation` bool

  Indicates whether the configuration was specified using a data annotation.

#### Returns

bool

  `true` if the given name and schema can be set for the hi-lo sequence.

### CanSetPostgresEnum(IConventionModelBuilder, string?, string, bool)

Returns a value indicating whether the given PostgreSQL extension can be registered in the model.

    public static bool CanSetPostgresEnum(this IConventionModelBuilder modelBuilder, string? schema, string name, bool fromDataAnnotation = false)

#### Parameters

`modelBuilder` IConventionModelBuilder

  The model builder.

`schema` string

  The schema in which to create the extension.

`name` string

  The name of the extension to create.

`fromDataAnnotation` bool

  Indicates whether the configuration was specified using a data annotation.

#### Returns

bool

  true if the given value can be set as the default increment for SQL Server IDENTITY.

#### Remarks

See Modeling entity types and relationships, and Accessing SQL Server and SQL Azure databases with EF Core for more information and examples.

### CanSetPostgresExtension(IConventionModelBuilder, string?, string, string?, bool)

Returns a value indicating whether the given PostgreSQL extension can be registered in the model.

    public static bool CanSetPostgresExtension(this IConventionModelBuilder modelBuilder, string? schema, string name, string? version = null, bool fromDataAnnotation = false)

#### Parameters

`modelBuilder` IConventionModelBuilder

  The model builder.

`schema` string

  The schema in which to create the extension.

`name` string

  The name of the extension to create.

`version` string

  The version of the extension.

`fromDataAnnotation` bool

  Indicates whether the configuration was specified using a data annotation.

#### Returns

bool

  true if the given value can be set as the default increment for SQL Server IDENTITY.

#### Remarks

See Modeling entity types and relationships, and Accessing SQL Server and SQL Azure databases with EF Core for more information and examples.

### CanSetValueGenerationStrategy(IConventionModelBuilder, NpgsqlValueGenerationStrategy?, bool)

Returns a value indicating whether the given value can be set as the default value generation strategy.

    public static bool CanSetValueGenerationStrategy(this IConventionModelBuilder modelBuilder, NpgsqlValueGenerationStrategy? valueGenerationStrategy, bool fromDataAnnotation = false)

#### Parameters

`modelBuilder` IConventionModelBuilder

  The model builder.

`valueGenerationStrategy` NpgsqlValueGenerationStrategy?

  The value generation strategy.

`fromDataAnnotation` bool

  Indicates whether the configuration was specified using a data annotation.

#### Returns

bool

  `true` if the given value can be set as the default value generation strategy.

### HasCollation(ModelBuilder, string, string, string?, bool?)

Creates a new collation in the database.

    public static ModelBuilder HasCollation(this ModelBuilder modelBuilder, string name, string locale, string? provider = null, bool? deterministic = null)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder on which to create the collation.

`name` string

  The name of the collation to create.

`locale` string

  Sets LC_COLLATE and LC_CTYPE at once.

`provider` string

  Specifies the provider to use for locale services associated with this collation. The available choices depend on the operating system and build options.

`deterministic` bool?

  Specifies whether the collation should use deterministic comparisons. Defaults to `true`.

#### Returns

ModelBuilder

  The same builder instance so that multiple calls can be chained.

#### Remarks

See https://www.postgresql.org/docs/current/sql-createcollation.html.

### HasCollation(ModelBuilder, string?, string, string, string?, bool?)

Creates a new collation in the database.

    public static ModelBuilder HasCollation(this ModelBuilder modelBuilder, string? schema, string name, string locale, string? provider = null, bool? deterministic = null)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder on which to create the collation.

`schema` string

  The schema in which to create the collation, or `null` for the default schema.

`name` string

  The name of the collation to create.

`locale` string

  Sets LC_COLLATE and LC_CTYPE at once.

`provider` string

  Specifies the provider to use for locale services associated with this collation. The available choices depend on the operating system and build options.

`deterministic` bool?

  Specifies whether the collation should use deterministic comparisons. Defaults to `true`.

#### Returns

ModelBuilder

  The same builder instance so that multiple calls can be chained.

#### Remarks

See https://www.postgresql.org/docs/current/sql-createcollation.html.

### HasCollation(ModelBuilder, string?, string, string, string, string?, bool?)

Creates a new collation in the database.

    public static ModelBuilder HasCollation(this ModelBuilder modelBuilder, string? schema, string name, string lcCollate, string lcCtype, string? provider = null, bool? deterministic = null)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder on which to create the collation.

`schema` string

  The schema in which to create the collation, or `null` for the default schema.

`name` string

  The name of the collation to create.

`lcCollate` string

  Use the specified operating system locale for the LC_COLLATE locale category.

`lcCtype` string

  Use the specified operating system locale for the LC_CTYPE locale category.

`provider` string

  Specifies the provider to use for locale services associated with this collation. The available choices depend on the operating system and build options.

`deterministic` bool?

  Specifies whether the collation should use deterministic comparisons. Defaults to `true`.

#### Returns

ModelBuilder

  The same builder instance so that multiple calls can be chained.

#### Remarks

See https://www.postgresql.org/docs/current/sql-createcollation.html.

### HasHiLoSequence(IConventionModelBuilder, string?, string?, bool)

Configures the database sequence used for the hi-lo pattern to generate values for key properties marked as OnAdd, when targeting PostgreSQL.

    public static IConventionSequenceBuilder? HasHiLoSequence(this IConventionModelBuilder modelBuilder, string? name, string? schema, bool fromDataAnnotation = false)

#### Parameters

`modelBuilder` IConventionModelBuilder

  The model builder.

`name` string

  The name of the sequence.

`schema` string

  The schema of the sequence.

`fromDataAnnotation` bool

  Indicates whether the configuration was specified using a data annotation.

#### Returns

IConventionSequenceBuilder

  A builder to further configure the sequence.

### HasPostgresEnum(IConventionModelBuilder, string?, string, string[])

Registers a user-defined enum type in the model.

    public static IConventionModelBuilder HasPostgresEnum(this IConventionModelBuilder modelBuilder, string? schema, string name, string[] labels)

#### Parameters

`modelBuilder` IConventionModelBuilder

  The model builder in which to create the enum type.

`schema` string

  The schema in which to create the enum type.

`name` string

  The name of the enum type to create.

`labels` string[]

  The enum label values.

#### Returns

IConventionModelBuilder

  The updated ModelBuilder.

#### Remarks

See: https://www.postgresql.org/docs/current/static/datatype-enum.html

#### Exceptions

ArgumentNullException

  builder

### HasPostgresEnum(ModelBuilder, string?, string, string[])

Registers a user-defined enum type in the model.

    public static ModelBuilder HasPostgresEnum(this ModelBuilder modelBuilder, string? schema, string name, string[] labels)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder in which to create the enum type.

`schema` string

  The schema in which to create the enum type.

`name` string

  The name of the enum type to create.

`labels` string[]

  The enum label values.

#### Returns

ModelBuilder

  The updated ModelBuilder.

#### Remarks

See: https://www.postgresql.org/docs/current/static/datatype-enum.html

#### Exceptions

ArgumentNullException

  builder

### HasPostgresEnum(ModelBuilder, string, string[])

Registers a user-defined enum type in the model.

    public static ModelBuilder HasPostgresEnum(this ModelBuilder modelBuilder, string name, string[] labels)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder in which to create the enum type.

`name` string

  The name of the enum type to create.

`labels` string[]

  The enum label values.

#### Returns

ModelBuilder

  The updated ModelBuilder.

#### Remarks

See: https://www.postgresql.org/docs/current/static/datatype-enum.html

#### Exceptions

ArgumentNullException

  builder

### HasPostgresEnum<TEnum>(ModelBuilder, string?, string?, INpgsqlNameTranslator?)

Registers a user-defined enum type in the model.

    public static ModelBuilder HasPostgresEnum<TEnum>(this ModelBuilder modelBuilder, string? schema = null, string? name = null, INpgsqlNameTranslator? nameTranslator = null) where TEnum : struct, Enum

#### Parameters

`modelBuilder` ModelBuilder

  The model builder in which to create the enum type.

`schema` string

  The schema in which to create the enum type.

`name` string

  The name of the enum type to create.

`nameTranslator` INpgsqlNameTranslator

  The translator for name and label inference. Defaults to NpgsqlSnakeCaseNameTranslator.

#### Returns

ModelBuilder

  The updated ModelBuilder.

#### Type Parameters

`TEnum`

#### Remarks

See: https://www.postgresql.org/docs/current/static/datatype-enum.html

#### Exceptions

ArgumentNullException

  builder

### HasPostgresExtension(IConventionModelBuilder, string, bool)

Registers a PostgreSQL extension in the model.

    public static IConventionModelBuilder? HasPostgresExtension(this IConventionModelBuilder modelBuilder, string name, bool fromDataAnnotation = false)

#### Parameters

`modelBuilder` IConventionModelBuilder

  The model builder in which to define the extension.

`name` string

  The name of the extension to create.

`fromDataAnnotation` bool

  Indicates whether the configuration was specified using a data annotation.

#### Returns

IConventionModelBuilder

  The same builder instance so that multiple calls can be chained.

#### Remarks

See: https://www.postgresql.org/docs/current/external-extensions.html

#### Exceptions

ArgumentNullException

  `modelBuilder`

### HasPostgresExtension(IConventionModelBuilder, string?, string, string?, bool)

Registers a PostgreSQL extension in the model.

    public static IConventionModelBuilder? HasPostgresExtension(this IConventionModelBuilder modelBuilder, string? schema, string name, string? version = null, bool fromDataAnnotation = false)

#### Parameters

`modelBuilder` IConventionModelBuilder

  The model builder in which to define the extension.

`schema` string

  The schema in which to create the extension.

`name` string

  The name of the extension to create.

`version` string

  The version of the extension.

`fromDataAnnotation` bool

  Indicates whether the configuration was specified using a data annotation.

#### Returns

IConventionModelBuilder

  The same builder instance so that multiple calls can be chained.

#### Remarks

See: https://www.postgresql.org/docs/current/external-extensions.html

#### Exceptions

ArgumentNullException

  `modelBuilder`

### HasPostgresExtension(ModelBuilder, string)

Registers a PostgreSQL extension in the model.

    public static ModelBuilder HasPostgresExtension(this ModelBuilder modelBuilder, string name)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder in which to define the extension.

`name` string

  The name of the extension to create.

#### Returns

ModelBuilder

  The same builder instance so that multiple calls can be chained.

#### Remarks

See: https://www.postgresql.org/docs/current/external-extensions.html

#### Exceptions

ArgumentNullException

  `modelBuilder`

### HasPostgresExtension(ModelBuilder, string?, string, string?)

Registers a PostgreSQL extension in the model.

    public static ModelBuilder HasPostgresExtension(this ModelBuilder modelBuilder, string? schema, string name, string? version = null)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder in which to define the extension.

`schema` string

  The schema in which to create the extension.

`name` string

  The name of the extension to create.

`version` string

  The version of the extension.

#### Returns

ModelBuilder

  The same builder instance so that multiple calls can be chained.

#### Remarks

See: https://www.postgresql.org/docs/current/external-extensions.html

#### Exceptions

ArgumentNullException

  `modelBuilder`

### HasPostgresRange(ModelBuilder, string, string)

Registers a user-defined range type in the model.

    public static ModelBuilder HasPostgresRange(this ModelBuilder modelBuilder, string name, string subtype)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder on which to create the range type.

`name` string

  The name of the range type to be created.

`subtype` string

  The subtype (or element type) of the range

#### Returns

ModelBuilder

#### Remarks

See https://www.postgresql.org/docs/current/static/rangetypes.html, https://www.postgresql.org/docs/current/static/sql-createtype.html,

### HasPostgresRange(ModelBuilder, string?, string, string, string?, string?, string?, string?)

Registers a user-defined range type in the model.

    public static ModelBuilder HasPostgresRange(this ModelBuilder modelBuilder, string? schema, string name, string subtype, string? canonicalFunction = null, string? subtypeOpClass = null, string? collation = null, string? subtypeDiff = null)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder on which to create the range type.

`schema` string

  The schema in which to create the range type.

`name` string

  The name of the range type to be created.

`subtype` string

  The subtype (or element type) of the range

`canonicalFunction` string

  An optional PostgreSQL function which converts range values to a canonical form.

`subtypeOpClass` string

  Used to specify a non-default operator class.

`collation` string

  Used to specify a non-default collation in the range's order.

`subtypeDiff` string

  An optional PostgreSQL function taking two values of the subtype type as argument, and return a double precision value representing the difference between the two given values.

#### Returns

ModelBuilder

#### Remarks

See https://www.postgresql.org/docs/current/static/rangetypes.html, https://www.postgresql.org/docs/current/static/sql-createtype.html,

### HasValueGenerationStrategy(IConventionModelBuilder, NpgsqlValueGenerationStrategy?, bool)

Configures the value generation strategy for the key property, when targeting PostgreSQL.

    public static IConventionModelBuilder? HasValueGenerationStrategy(this IConventionModelBuilder modelBuilder, NpgsqlValueGenerationStrategy? valueGenerationStrategy, bool fromDataAnnotation = false)

#### Parameters

`modelBuilder` IConventionModelBuilder

  The builder for the property being configured.

`valueGenerationStrategy` NpgsqlValueGenerationStrategy?

  The value generation strategy.

`fromDataAnnotation` bool

  Indicates whether the configuration was specified using a data annotation.

#### Returns

IConventionModelBuilder

  The same builder instance if the configuration was applied, `null` otherwise.

### UseDatabaseTemplate(ModelBuilder, string)

Specifies the PostgreSQL database to use as a template when creating a new database for this model.

    public static ModelBuilder UseDatabaseTemplate(this ModelBuilder modelBuilder, string templateDatabaseName)

#### Parameters

`modelBuilder` ModelBuilder
`templateDatabaseName` string

#### Returns

ModelBuilder

### UseHiLo(ModelBuilder, string?, string?)

Configures the model to use a sequence-based hi-lo pattern to generate values for properties marked as OnAdd, when targeting PostgreSQL.

    public static ModelBuilder UseHiLo(this ModelBuilder modelBuilder, string? name = null, string? schema = null)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder.

`name` string

  The name of the sequence.

`schema` string

  The schema of the sequence.

#### Returns

ModelBuilder

  The same builder instance so that multiple calls can be chained.

### UseIdentityAlwaysColumns(ModelBuilder)

Configures the model to use the PostgreSQL IDENTITY feature to generate values for properties marked as OnAdd, when targeting PostgreSQL. Values for these columns will always be generated as identity, and the application will not be able to override this behavior by providing a value.

Available only starting PostgreSQL 10.

    public static ModelBuilder UseIdentityAlwaysColumns(this ModelBuilder modelBuilder)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder.

#### Returns

ModelBuilder

  The same builder instance so that multiple calls can be chained.

### UseIdentityByDefaultColumns(ModelBuilder)

Configures the model to use the PostgreSQL IDENTITY feature to generate values for properties marked as OnAdd, when targeting PostgreSQL. Values for these columns will be generated as identity by default, but the application will be able to override this behavior by providing a value.

This is the default behavior when targeting PostgreSQL. Available only starting PostgreSQL 10.

    public static ModelBuilder UseIdentityByDefaultColumns(this ModelBuilder modelBuilder)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder.

#### Returns

ModelBuilder

  The same builder instance so that multiple calls can be chained.

### UseIdentityColumns(ModelBuilder)

Configures the model to use the PostgreSQL IDENTITY feature to generate values for properties marked as OnAdd, when targeting PostgreSQL. Values for these columns will be generated as identity by default, but the application will be able to override this behavior by providing a value.

This is the default behavior when targeting PostgreSQL. Available only starting PostgreSQL 10.

    public static ModelBuilder UseIdentityColumns(this ModelBuilder modelBuilder)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder.

#### Returns

ModelBuilder

  The same builder instance so that multiple calls can be chained.

### UseKeySequences(ModelBuilder, string?, string?)

Configures the model to use a sequence per hierarchy to generate values for key properties marked as OnAdd, when targeting PostgreSQL.

    public static ModelBuilder UseKeySequences(this ModelBuilder modelBuilder, string? nameSuffix = null, string? schema = null)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder.

`nameSuffix` string

  The name that will suffix the table name for each sequence created automatically.

`schema` string

  The schema of the sequence.

#### Returns

ModelBuilder

  The same builder instance so that multiple calls can be chained.

### UseSerialColumns(ModelBuilder)

Configures the model to use the PostgreSQL SERIAL feature to generate values for properties marked as OnAdd, when targeting PostgreSQL.

This option should be considered deprecated starting with PostgreSQL 10, consider using UseIdentityColumns(ModelBuilder) instead.

    public static ModelBuilder UseSerialColumns(this ModelBuilder modelBuilder)

#### Parameters

`modelBuilder` ModelBuilder

  The model builder.

#### Returns

ModelBuilder

  The same builder instance so that multiple calls can be chained.

### UseTablespace(ModelBuilder, string)

Specifies the PostgreSQL tablespace in which to place the new database created for this model.

    public static ModelBuilder UseTablespace(this ModelBuilder modelBuilder, string tablespace)

#### Parameters

`modelBuilder` ModelBuilder
`tablespace` string

#### Returns

ModelBuilder