Class NpgsqlModelBuilderExtensions
- Namespace
- Microsoft.EntityFrameworkCore
- Assembly
- Npgsql.EntityFrameworkCore.PostgreSQL.dll
Npgsql-specific extension methods for ModelBuilder.
public static class NpgsqlModelBuilderExtensions
- Inheritance
-
NpgsqlModelBuilderExtensions
- Inherited Members
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
modelBuilderIConventionModelBuilderThe model builder.
namestringThe name of the sequence.
schemastringThe schema of the sequence.
fromDataAnnotationboolIndicates whether the configuration was specified using a data annotation.
Returns
- bool
trueif 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
modelBuilderIConventionModelBuilderThe model builder.
schemastringThe schema in which to create the extension.
namestringThe name of the extension to create.
fromDataAnnotationboolIndicates whether the configuration was specified using a data annotation.
Returns
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
modelBuilderIConventionModelBuilderThe model builder.
schemastringThe schema in which to create the extension.
namestringThe name of the extension to create.
versionstringThe version of the extension.
fromDataAnnotationboolIndicates whether the configuration was specified using a data annotation.
Returns
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
modelBuilderIConventionModelBuilderThe model builder.
valueGenerationStrategyNpgsqlValueGenerationStrategy?The value generation strategy.
fromDataAnnotationboolIndicates whether the configuration was specified using a data annotation.
Returns
- bool
trueif 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
modelBuilderModelBuilderThe model builder on which to create the collation.
namestringThe name of the collation to create.
localestringSets LC_COLLATE and LC_CTYPE at once.
providerstringSpecifies the provider to use for locale services associated with this collation. The available choices depend on the operating system and build options.
deterministicbool?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
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
modelBuilderModelBuilderThe model builder on which to create the collation.
schemastringThe schema in which to create the collation, or
nullfor the default schema.namestringThe name of the collation to create.
localestringSets LC_COLLATE and LC_CTYPE at once.
providerstringSpecifies the provider to use for locale services associated with this collation. The available choices depend on the operating system and build options.
deterministicbool?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
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
modelBuilderModelBuilderThe model builder on which to create the collation.
schemastringThe schema in which to create the collation, or
nullfor the default schema.namestringThe name of the collation to create.
lcCollatestringUse the specified operating system locale for the LC_COLLATE locale category.
lcCtypestringUse the specified operating system locale for the LC_CTYPE locale category.
providerstringSpecifies the provider to use for locale services associated with this collation. The available choices depend on the operating system and build options.
deterministicbool?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
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
modelBuilderIConventionModelBuilderThe model builder.
namestringThe name of the sequence.
schemastringThe schema of the sequence.
fromDataAnnotationboolIndicates 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
modelBuilderIConventionModelBuilderThe model builder in which to create the enum type.
schemastringThe schema in which to create the enum type.
namestringThe name of the enum type to create.
labelsstring[]The enum label values.
Returns
- IConventionModelBuilder
The updated ModelBuilder.
Remarks
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
modelBuilderModelBuilderThe model builder in which to create the enum type.
schemastringThe schema in which to create the enum type.
namestringThe name of the enum type to create.
labelsstring[]The enum label values.
Returns
- ModelBuilder
The updated ModelBuilder.
Remarks
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
modelBuilderModelBuilderThe model builder in which to create the enum type.
namestringThe name of the enum type to create.
labelsstring[]The enum label values.
Returns
- ModelBuilder
The updated ModelBuilder.
Remarks
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
modelBuilderModelBuilderThe model builder in which to create the enum type.
schemastringThe schema in which to create the enum type.
namestringThe name of the enum type to create.
nameTranslatorINpgsqlNameTranslatorThe translator for name and label inference. Defaults to NpgsqlSnakeCaseNameTranslator.
Returns
- ModelBuilder
The updated ModelBuilder.
Type Parameters
TEnum
Remarks
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
modelBuilderIConventionModelBuilderThe model builder in which to define the extension.
namestringThe name of the extension to create.
fromDataAnnotationboolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
The same builder instance so that multiple calls can be chained.
Remarks
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
modelBuilderIConventionModelBuilderThe model builder in which to define the extension.
schemastringThe schema in which to create the extension.
namestringThe name of the extension to create.
versionstringThe version of the extension.
fromDataAnnotationboolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
The same builder instance so that multiple calls can be chained.
Remarks
Exceptions
- ArgumentNullException
modelBuilder
HasPostgresExtension(ModelBuilder, string)
Registers a PostgreSQL extension in the model.
public static ModelBuilder HasPostgresExtension(this ModelBuilder modelBuilder, string name)
Parameters
modelBuilderModelBuilderThe model builder in which to define the extension.
namestringThe name of the extension to create.
Returns
- ModelBuilder
The same builder instance so that multiple calls can be chained.
Remarks
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
modelBuilderModelBuilderThe model builder in which to define the extension.
schemastringThe schema in which to create the extension.
namestringThe name of the extension to create.
versionstringThe version of the extension.
Returns
- ModelBuilder
The same builder instance so that multiple calls can be chained.
Remarks
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
modelBuilderModelBuilderThe model builder on which to create the range type.
namestringThe name of the range type to be created.
subtypestringThe subtype (or element type) of the range
Returns
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
modelBuilderModelBuilderThe model builder on which to create the range type.
schemastringThe schema in which to create the range type.
namestringThe name of the range type to be created.
subtypestringThe subtype (or element type) of the range
canonicalFunctionstringAn optional PostgreSQL function which converts range values to a canonical form.
subtypeOpClassstringUsed to specify a non-default operator class.
collationstringUsed to specify a non-default collation in the range's order.
subtypeDiffstringAn 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
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
modelBuilderIConventionModelBuilderThe builder for the property being configured.
valueGenerationStrategyNpgsqlValueGenerationStrategy?The value generation strategy.
fromDataAnnotationboolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
The same builder instance if the configuration was applied,
nullotherwise.
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
modelBuilderModelBuildertemplateDatabaseNamestring
Returns
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
modelBuilderModelBuilderThe model builder.
namestringThe name of the sequence.
schemastringThe 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
modelBuilderModelBuilderThe 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
modelBuilderModelBuilderThe 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
modelBuilderModelBuilderThe 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
modelBuilderModelBuilderThe model builder.
nameSuffixstringThe name that will suffix the table name for each sequence created automatically.
schemastringThe 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
modelBuilderModelBuilderThe 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
modelBuilderModelBuildertablespacestring