Class NpgsqlModelBuilderExtensions
Npgsql-specific extension methods for
Namespace: Microsoft.EntityFrameworkCore
Assembly: Npgsql.EntityFrameworkCore.PostgreSQL.dll
Syntax
public static class NpgsqlModelBuilderExtensions
Methods
| Improve this Doc View SourceCanSetDefaultColumnCollation(IConventionModelBuilder, string?, bool)
Returns a value indicating whether the given value can be set as the default column collation.
Declaration
public static bool CanSetDefaultColumnCollation(this IConventionModelBuilder modelBuilder, string? collation, bool fromDataAnnotation = false)
Parameters
Type | Name | Description |
---|---|---|
IConventionModelBuilder | modelBuilder | The model builder. |
string? | collation | The collation. |
bool | fromDataAnnotation | Indicates whether the configuration was specified using a data annotation. |
Returns
Type | Description |
---|---|
bool |
|
CanSetHiLoSequence(IConventionModelBuilder, string?, string?, bool)
Returns a value indicating whether the given name and schema can be set for the hi-lo sequence.
Declaration
public static bool CanSetHiLoSequence(this IConventionModelBuilder modelBuilder, string? name, string? schema, bool fromDataAnnotation = false)
Parameters
Type | Name | Description |
---|---|---|
IConventionModelBuilder | modelBuilder | The model builder. |
string? | name | The name of the sequence. |
string? | schema | The schema of the sequence. |
bool | fromDataAnnotation | Indicates whether the configuration was specified using a data annotation. |
Returns
Type | Description |
---|---|
bool |
|
CanSetPostgresExtension(IConventionModelBuilder, string?, string, string?, bool)
Returns a value indicating whether the given PostgreSQL extension can be registered in the model.
Declaration
public static bool CanSetPostgresExtension(this IConventionModelBuilder modelBuilder, string? schema, string name, string? version = null, bool fromDataAnnotation = false)
Parameters
Type | Name | Description |
---|---|---|
IConventionModelBuilder | modelBuilder | The model builder. |
string? | schema | The schema in which to create the extension. |
string | name | The name of the extension to create. |
string? | version | The version of the extension. |
bool | fromDataAnnotation | Indicates whether the configuration was specified using a data annotation. |
Returns
Type | Description |
---|---|
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.
Declaration
public static bool CanSetValueGenerationStrategy(this IConventionModelBuilder modelBuilder, NpgsqlValueGenerationStrategy? valueGenerationStrategy, bool fromDataAnnotation = false)
Parameters
Type | Name | Description |
---|---|---|
IConventionModelBuilder | modelBuilder | The model builder. |
NpgsqlValueGenerationStrategy? | valueGenerationStrategy | The value generation strategy. |
bool | fromDataAnnotation | Indicates whether the configuration was specified using a data annotation. |
Returns
Type | Description |
---|---|
bool |
|
HasCollation(ModelBuilder, string?, string, string, string?, bool?)
Creates a new collation in the database.
Declaration
public static ModelBuilder HasCollation(this ModelBuilder modelBuilder, string? schema, string name, string locale, string? provider = null, bool? deterministic = null)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder on which to create the collation. |
string? | schema | The schema in which to create the collation, or |
string | name | The name of the collation to create. |
string | locale | Sets LC_COLLATE and LC_CTYPE at once. |
string? | provider | Specifies the provider to use for locale services associated with this collation. The available choices depend on the operating system and build options. |
bool? | deterministic | Specifies whether the collation should use deterministic comparisons.
Defaults to |
Returns
Type | Description |
---|---|
ModelBuilder | The same builder instance so that multiple calls can be chained. |
Remarks
| Improve this Doc View SourceHasCollation(ModelBuilder, string?, string, string, string, string?, bool?)
Creates a new collation in the database.
Declaration
public static ModelBuilder HasCollation(this ModelBuilder modelBuilder, string? schema, string name, string lcCollate, string lcCtype, string? provider = null, bool? deterministic = null)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder on which to create the collation. |
string? | schema | The schema in which to create the collation, or |
string | name | The name of the collation to create. |
string | lcCollate | Use the specified operating system locale for the LC_COLLATE locale category. |
string | lcCtype | Use the specified operating system locale for the LC_CTYPE locale category. |
string? | provider | Specifies the provider to use for locale services associated with this collation. The available choices depend on the operating system and build options. |
bool? | deterministic | Specifies whether the collation should use deterministic comparisons.
Defaults to |
Returns
Type | Description |
---|---|
ModelBuilder | The same builder instance so that multiple calls can be chained. |
Remarks
| Improve this Doc View SourceHasCollation(ModelBuilder, string, string, string?, bool?)
Creates a new collation in the database.
Declaration
public static ModelBuilder HasCollation(this ModelBuilder modelBuilder, string name, string locale, string? provider = null, bool? deterministic = null)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder on which to create the collation. |
string | name | The name of the collation to create. |
string | locale | Sets LC_COLLATE and LC_CTYPE at once. |
string? | provider | Specifies the provider to use for locale services associated with this collation. The available choices depend on the operating system and build options. |
bool? | deterministic | Specifies whether the collation should use deterministic comparisons.
Defaults to |
Returns
Type | Description |
---|---|
ModelBuilder | The same builder instance so that multiple calls can be chained. |
Remarks
| Improve this Doc View SourceHasHiLoSequence(IConventionModelBuilder, string?, string?, bool)
Configures the database sequence used for the hi-lo pattern to generate values for key properties
marked as
Declaration
public static IConventionSequenceBuilder? HasHiLoSequence(this IConventionModelBuilder modelBuilder, string? name, string? schema, bool fromDataAnnotation = false)
Parameters
Type | Name | Description |
---|---|---|
IConventionModelBuilder | modelBuilder | The model builder. |
string? | name | The name of the sequence. |
string? | schema | The schema of the sequence. |
bool | fromDataAnnotation | Indicates whether the configuration was specified using a data annotation. |
Returns
Type | Description |
---|---|
IConventionSequenceBuilder? | A builder to further configure the sequence. |
HasPostgresEnum(ModelBuilder, string?, string, string[])
Registers a user-defined enum type in the model.
Declaration
public static ModelBuilder HasPostgresEnum(this ModelBuilder modelBuilder, string? schema, string name, string[] labels)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder in which to create the enum type. |
string? | schema | The schema in which to create the enum type. |
string | name | The name of the enum type to create. |
string[] | labels | The enum label values. |
Returns
Type | Description |
---|---|
ModelBuilder | The updated |
Remarks
| Improve this Doc View SourceHasPostgresEnum(ModelBuilder, string, string[])
Registers a user-defined enum type in the model.
Declaration
public static ModelBuilder HasPostgresEnum(this ModelBuilder modelBuilder, string name, string[] labels)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder in which to create the enum type. |
string | name | The name of the enum type to create. |
string[] | labels | The enum label values. |
Returns
Type | Description |
---|---|
ModelBuilder | The updated |
Remarks
| Improve this Doc View SourceHasPostgresEnum<TEnum>(ModelBuilder, string?, string?, INpgsqlNameTranslator?)
Registers a user-defined enum type in the model.
Declaration
public static ModelBuilder HasPostgresEnum<TEnum>(this ModelBuilder modelBuilder, string? schema = null, string? name = null, INpgsqlNameTranslator? nameTranslator = null) where TEnum : struct, Enum
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder in which to create the enum type. |
string? | schema | The schema in which to create the enum type. |
string? | name | The name of the enum type to create. |
INpgsqlNameTranslator? | nameTranslator | The translator for name and label inference.
Defaults to |
Returns
Type | Description |
---|---|
ModelBuilder | The updated |
Type Parameters
Name | Description |
---|---|
TEnum |
Remarks
| Improve this Doc View SourceHasPostgresExtension(IConventionModelBuilder, string?, string, string?, bool)
Registers a PostgreSQL extension in the model.
Declaration
public static IConventionModelBuilder? HasPostgresExtension(this IConventionModelBuilder modelBuilder, string? schema, string name, string? version = null, bool fromDataAnnotation = false)
Parameters
Type | Name | Description |
---|---|---|
IConventionModelBuilder | modelBuilder | The model builder in which to define the extension. |
string? | schema | The schema in which to create the extension. |
string | name | The name of the extension to create. |
string? | version | The version of the extension. |
bool | fromDataAnnotation | Indicates whether the configuration was specified using a data annotation. |
Returns
Type | Description |
---|---|
IConventionModelBuilder? | The same builder instance so that multiple calls can be chained. |
Remarks
| Improve this Doc View SourceHasPostgresExtension(IConventionModelBuilder, string, bool)
Registers a PostgreSQL extension in the model.
Declaration
public static IConventionModelBuilder? HasPostgresExtension(this IConventionModelBuilder modelBuilder, string name, bool fromDataAnnotation = false)
Parameters
Type | Name | Description |
---|---|---|
IConventionModelBuilder | modelBuilder | The model builder in which to define the extension. |
string | name | The name of the extension to create. |
bool | fromDataAnnotation | Indicates whether the configuration was specified using a data annotation. |
Returns
Type | Description |
---|---|
IConventionModelBuilder? | The same builder instance so that multiple calls can be chained. |
Remarks
| Improve this Doc View SourceHasPostgresExtension(ModelBuilder, string?, string, string?)
Registers a PostgreSQL extension in the model.
Declaration
public static ModelBuilder HasPostgresExtension(this ModelBuilder modelBuilder, string? schema, string name, string? version = null)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder in which to define the extension. |
string? | schema | The schema in which to create the extension. |
string | name | The name of the extension to create. |
string? | version | The version of the extension. |
Returns
Type | Description |
---|---|
ModelBuilder | The same builder instance so that multiple calls can be chained. |
Remarks
| Improve this Doc View SourceHasPostgresExtension(ModelBuilder, string)
Registers a PostgreSQL extension in the model.
Declaration
public static ModelBuilder HasPostgresExtension(this ModelBuilder modelBuilder, string name)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder in which to define the extension. |
string | name | The name of the extension to create. |
Returns
Type | Description |
---|---|
ModelBuilder | The same builder instance so that multiple calls can be chained. |
Remarks
| Improve this Doc View SourceHasPostgresRange(ModelBuilder, string?, string, string, string?, string?, string?, string?)
Registers a user-defined range type in the model.
Declaration
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
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder on which to create the range type. |
string? | schema | The schema in which to create the range type. |
string | name | The name of the range type to be created. |
string | subtype | The subtype (or element type) of the range |
string? | canonicalFunction | An optional PostgreSQL function which converts range values to a canonical form. |
string? | subtypeOpClass | Used to specify a non-default operator class. |
string? | collation | Used to specify a non-default collation in the range's order. |
string? | subtypeDiff | 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
Type | Description |
---|---|
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)
Registers a user-defined range type in the model.
Declaration
public static ModelBuilder HasPostgresRange(this ModelBuilder modelBuilder, string name, string subtype)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder on which to create the range type. |
string | name | The name of the range type to be created. |
string | subtype | The subtype (or element type) of the range |
Returns
Type | Description |
---|---|
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.
Declaration
public static IConventionModelBuilder? HasValueGenerationStrategy(this IConventionModelBuilder modelBuilder, NpgsqlValueGenerationStrategy? valueGenerationStrategy, bool fromDataAnnotation = false)
Parameters
Type | Name | Description |
---|---|---|
IConventionModelBuilder | modelBuilder | The builder for the property being configured. |
NpgsqlValueGenerationStrategy? | valueGenerationStrategy | The value generation strategy. |
bool | fromDataAnnotation | Indicates whether the configuration was specified using a data annotation. |
Returns
Type | Description |
---|---|
IConventionModelBuilder? | The same builder instance if the configuration was applied, |
UseDatabaseTemplate(ModelBuilder, string)
Specifies the PostgreSQL database to use as a template when creating a new database for this model.
Declaration
public static ModelBuilder UseDatabaseTemplate(this ModelBuilder modelBuilder, string templateDatabaseName)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | |
string | templateDatabaseName |
Returns
Type | Description |
---|---|
ModelBuilder |
UseDefaultColumnCollation(IConventionModelBuilder, string?, bool)
Configures the default collation for all columns in the database. This causes EF Core to specify an explicit collation when creating each column (unless overridden).
Declaration
public static IConventionModelBuilder? UseDefaultColumnCollation(this IConventionModelBuilder modelBuilder, string? collation, bool fromDataAnnotation = false)
Parameters
Type | Name | Description |
---|---|---|
IConventionModelBuilder | modelBuilder | The model builder. |
string? | collation | The collation. |
bool | fromDataAnnotation | Indicates whether the configuration was specified using a data annotation. |
Returns
Type | Description |
---|---|
IConventionModelBuilder? | A builder to further configure the property. |
Remarks
An alternative is to specify a database collation via CREATE DATABASE
instead of for each and every column. However,
PostgreSQL support is limited for the collations that can be specific via this mechanism; ICU collations -
which include all case-insensitive collations - are currently unsupported.
For more information, see https://www.postgresql.org/docs/current/collation.html.
UseDefaultColumnCollation(ModelBuilder, string?)
Configures the default collation for all columns in the database. This causes EF Core to specify an explicit collation when creating each column (unless overridden).
Declaration
public static ModelBuilder UseDefaultColumnCollation(this ModelBuilder modelBuilder, string? collation)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder. |
string? | collation | The collation. |
Returns
Type | Description |
---|---|
ModelBuilder | A builder to further configure the property. |
Remarks
An alternative is to specify a database collation via CREATE DATABASE
instead of for each and every column. However,
PostgreSQL support is limited for the collations that can be specific via this mechanism; ICU collations -
which include all case-insensitive collations - are currently unsupported.
For more information, see https://www.postgresql.org/docs/current/collation.html.
UseHiLo(ModelBuilder, string?, string?)
Configures the model to use a sequence-based hi-lo pattern to generate values for properties
marked as
Declaration
public static ModelBuilder UseHiLo(this ModelBuilder modelBuilder, string? name = null, string? schema = null)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder. |
string? | name | The name of the sequence. |
string? | schema | The schema of the sequence. |
Returns
Type | Description |
---|---|
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
Available only starting PostgreSQL 10.
Declaration
public static ModelBuilder UseIdentityAlwaysColumns(this ModelBuilder modelBuilder)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder. |
Returns
Type | Description |
---|---|
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
This is the default behavior when targeting PostgreSQL. Available only starting PostgreSQL 10.
Declaration
public static ModelBuilder UseIdentityByDefaultColumns(this ModelBuilder modelBuilder)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder. |
Returns
Type | Description |
---|---|
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
This is the default behavior when targeting PostgreSQL. Available only starting PostgreSQL 10.
Declaration
public static ModelBuilder UseIdentityColumns(this ModelBuilder modelBuilder)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder. |
Returns
Type | Description |
---|---|
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
Declaration
public static ModelBuilder UseKeySequences(this ModelBuilder modelBuilder, string? nameSuffix = null, string? schema = null)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder. |
string? | nameSuffix | The name that will suffix the table name for each sequence created automatically. |
string? | schema | The schema of the sequence. |
Returns
Type | Description |
---|---|
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
This option should be considered deprecated starting with PostgreSQL 10, consider using UseIdentityColumns(ModelBuilder) instead.
Declaration
public static ModelBuilder UseSerialColumns(this ModelBuilder modelBuilder)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | The model builder. |
Returns
Type | Description |
---|---|
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.
Declaration
public static ModelBuilder UseTablespace(this ModelBuilder modelBuilder, string tablespace)
Parameters
Type | Name | Description |
---|---|---|
ModelBuilder | modelBuilder | |
string | tablespace |
Returns
Type | Description |
---|---|
ModelBuilder |