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
- modelBuilderIConventionModelBuilder
- The model builder. 
- namestring
- The name of the sequence. 
- schemastring
- The schema of the sequence. 
- fromDataAnnotationbool
- Indicates 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
- modelBuilderIConventionModelBuilder
- The model builder. 
- schemastring
- The schema in which to create the extension. 
- namestring
- The name of the extension to create. 
- fromDataAnnotationbool
- Indicates 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
- modelBuilderIConventionModelBuilder
- The model builder. 
- schemastring
- The schema in which to create the extension. 
- namestring
- The name of the extension to create. 
- versionstring
- The version of the extension. 
- fromDataAnnotationbool
- Indicates 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
- modelBuilderIConventionModelBuilder
- The model builder. 
- valueGenerationStrategyNpgsqlValueGenerationStrategy?
- The value generation strategy. 
- fromDataAnnotationbool
- Indicates 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
- modelBuilderModelBuilder
- The model builder on which to create the collation. 
- namestring
- The name of the collation to create. 
- localestring
- Sets LC_COLLATE and LC_CTYPE at once. 
- providerstring
- Specifies 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
- modelBuilderModelBuilder
- The model builder on which to create the collation. 
- schemastring
- The schema in which to create the collation, or - nullfor the default schema.
- namestring
- The name of the collation to create. 
- localestring
- Sets LC_COLLATE and LC_CTYPE at once. 
- providerstring
- Specifies 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
- modelBuilderModelBuilder
- The model builder on which to create the collation. 
- schemastring
- The schema in which to create the collation, or - nullfor the default schema.
- namestring
- The name of the collation to create. 
- lcCollatestring
- Use the specified operating system locale for the LC_COLLATE locale category. 
- lcCtypestring
- Use the specified operating system locale for the LC_CTYPE locale category. 
- providerstring
- Specifies 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
- modelBuilderIConventionModelBuilder
- The model builder. 
- namestring
- The name of the sequence. 
- schemastring
- The schema of the sequence. 
- fromDataAnnotationbool
- 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
- modelBuilderIConventionModelBuilder
- The model builder in which to create the enum type. 
- schemastring
- The schema in which to create the enum type. 
- namestring
- The 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
- modelBuilderModelBuilder
- The model builder in which to create the enum type. 
- schemastring
- The schema in which to create the enum type. 
- namestring
- The 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
- modelBuilderModelBuilder
- The model builder in which to create the enum type. 
- namestring
- The 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, EnumParameters
- modelBuilderModelBuilder
- The model builder in which to create the enum type. 
- schemastring
- The schema in which to create the enum type. 
- namestring
- The name of the enum type to create. 
- nameTranslatorINpgsqlNameTranslator
- The 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
- modelBuilderIConventionModelBuilder
- The model builder in which to define the extension. 
- namestring
- The name of the extension to create. 
- fromDataAnnotationbool
- Indicates 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
- modelBuilderIConventionModelBuilder
- The model builder in which to define the extension. 
- schemastring
- The schema in which to create the extension. 
- namestring
- The name of the extension to create. 
- versionstring
- The version of the extension. 
- fromDataAnnotationbool
- Indicates 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
- modelBuilderModelBuilder
- The model builder in which to define the extension. 
- namestring
- The 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
- modelBuilderModelBuilder
- The model builder in which to define the extension. 
- schemastring
- The schema in which to create the extension. 
- namestring
- The name of the extension to create. 
- versionstring
- The 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
- modelBuilderModelBuilder
- The model builder on which to create the range type. 
- namestring
- The name of the range type to be created. 
- subtypestring
- The 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
- modelBuilderModelBuilder
- The model builder on which to create the range type. 
- schemastring
- The schema in which to create the range type. 
- namestring
- The name of the range type to be created. 
- subtypestring
- The subtype (or element type) of the range 
- canonicalFunctionstring
- An optional PostgreSQL function which converts range values to a canonical form. 
- subtypeOpClassstring
- Used to specify a non-default operator class. 
- collationstring
- Used to specify a non-default collation in the range's order. 
- subtypeDiffstring
- 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
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
- modelBuilderIConventionModelBuilder
- The builder for the property being configured. 
- valueGenerationStrategyNpgsqlValueGenerationStrategy?
- The value generation strategy. 
- fromDataAnnotationbool
- Indicates 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
- modelBuilderModelBuilder
- templateDatabaseNamestring
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
- modelBuilderModelBuilder
- The model builder. 
- namestring
- The name of the sequence. 
- schemastring
- 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
- modelBuilderModelBuilder
- 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
- modelBuilderModelBuilder
- 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
- modelBuilderModelBuilder
- 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
- modelBuilderModelBuilder
- The model builder. 
- nameSuffixstring
- The name that will suffix the table name for each sequence created automatically. 
- schemastring
- 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
- modelBuilderModelBuilder
- 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
- modelBuilderModelBuilder
- tablespacestring