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
modelBuilder
IConventionModelBuilderThe model builder.
name
stringThe name of the sequence.
schema
stringThe schema of the sequence.
fromDataAnnotation
boolIndicates 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
IConventionModelBuilderThe model builder.
schema
stringThe schema in which to create the extension.
name
stringThe name of the extension to create.
fromDataAnnotation
boolIndicates 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
modelBuilder
IConventionModelBuilderThe model builder.
schema
stringThe schema in which to create the extension.
name
stringThe name of the extension to create.
version
stringThe version of the extension.
fromDataAnnotation
boolIndicates 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
modelBuilder
IConventionModelBuilderThe model builder.
valueGenerationStrategy
NpgsqlValueGenerationStrategy?The value generation strategy.
fromDataAnnotation
boolIndicates 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
ModelBuilderThe model builder on which to create the collation.
name
stringThe name of the collation to create.
locale
stringSets LC_COLLATE and LC_CTYPE at once.
provider
stringSpecifies 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
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
ModelBuilderThe model builder on which to create the collation.
schema
stringThe schema in which to create the collation, or
null
for the default schema.name
stringThe name of the collation to create.
locale
stringSets LC_COLLATE and LC_CTYPE at once.
provider
stringSpecifies 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
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
ModelBuilderThe model builder on which to create the collation.
schema
stringThe schema in which to create the collation, or
null
for the default schema.name
stringThe name of the collation to create.
lcCollate
stringUse the specified operating system locale for the LC_COLLATE locale category.
lcCtype
stringUse the specified operating system locale for the LC_CTYPE locale category.
provider
stringSpecifies 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
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
IConventionModelBuilderThe model builder.
name
stringThe name of the sequence.
schema
stringThe schema of the sequence.
fromDataAnnotation
boolIndicates 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
IConventionModelBuilderThe model builder in which to create the enum type.
schema
stringThe schema in which to create the enum type.
name
stringThe name of the enum type to create.
labels
string[]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
modelBuilder
ModelBuilderThe model builder in which to create the enum type.
schema
stringThe schema in which to create the enum type.
name
stringThe name of the enum type to create.
labels
string[]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
modelBuilder
ModelBuilderThe model builder in which to create the enum type.
name
stringThe name of the enum type to create.
labels
string[]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
modelBuilder
ModelBuilderThe model builder in which to create the enum type.
schema
stringThe schema in which to create the enum type.
name
stringThe name of the enum type to create.
nameTranslator
INpgsqlNameTranslatorThe 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
modelBuilder
IConventionModelBuilderThe model builder in which to define the extension.
name
stringThe name of the extension to create.
fromDataAnnotation
boolIndicates 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
modelBuilder
IConventionModelBuilderThe model builder in which to define the extension.
schema
stringThe schema in which to create the extension.
name
stringThe name of the extension to create.
version
stringThe version of the extension.
fromDataAnnotation
boolIndicates 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
modelBuilder
ModelBuilderThe model builder in which to define the extension.
name
stringThe 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
modelBuilder
ModelBuilderThe model builder in which to define the extension.
schema
stringThe schema in which to create the extension.
name
stringThe name of the extension to create.
version
stringThe 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
modelBuilder
ModelBuilderThe model builder on which to create the range type.
name
stringThe name of the range type to be created.
subtype
stringThe 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
modelBuilder
ModelBuilderThe model builder on which to create the range type.
schema
stringThe schema in which to create the range type.
name
stringThe name of the range type to be created.
subtype
stringThe subtype (or element type) of the range
canonicalFunction
stringAn optional PostgreSQL function which converts range values to a canonical form.
subtypeOpClass
stringUsed to specify a non-default operator class.
collation
stringUsed to specify a non-default collation in the range's order.
subtypeDiff
stringAn 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
modelBuilder
IConventionModelBuilderThe builder for the property being configured.
valueGenerationStrategy
NpgsqlValueGenerationStrategy?The value generation strategy.
fromDataAnnotation
boolIndicates 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
ModelBuildertemplateDatabaseName
string
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
modelBuilder
ModelBuilderThe model builder.
name
stringThe name of the sequence.
schema
stringThe 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
ModelBuilderThe 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
ModelBuilderThe 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
ModelBuilderThe 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
ModelBuilderThe model builder.
nameSuffix
stringThe name that will suffix the table name for each sequence created automatically.
schema
stringThe 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
ModelBuilderThe 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
ModelBuildertablespace
string