Table of Contents

Class RelationalPropertyBuilderExtensions

Namespace
Microsoft.EntityFrameworkCore
Assembly
Microsoft.EntityFrameworkCore.Relational.dll

Relational database specific extension methods for Microsoft.EntityFrameworkCore.Metadata.Builders.PropertyBuilder.

public static class RelationalPropertyBuilderExtensions
Inheritance
RelationalPropertyBuilderExtensions
Inherited Members

Methods

CanSetCollation(IConventionPropertyBuilder, string, bool)

Returns a value indicating whether the given value can be set as the collation.

public static bool CanSetCollation(this IConventionPropertyBuilder propertyBuilder, string collation, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

collation string

The collation.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given value can be set as default for the column.

CanSetColumnName(IConventionPropertyBuilder, string, in StoreObjectIdentifier, bool)

Returns a value indicating whether the given column for a particular table-like store object can be set for the property.

public static bool CanSetColumnName(this IConventionPropertyBuilder propertyBuilder, string name, in StoreObjectIdentifier storeObject, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

name string

The name of the column.

storeObject StoreObjectIdentifier

The identifier of the store object.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the property can be mapped to the given column.

CanSetColumnName(IConventionPropertyBuilder, string, bool)

Returns a value indicating whether the given column can be set for the property.

public static bool CanSetColumnName(this IConventionPropertyBuilder propertyBuilder, string name, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

name string

The name of the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the property can be mapped to the given column.

CanSetColumnType(IConventionPropertyBuilder, string, bool)

Returns a value indicating whether the given data type can be set for the property.

public static bool CanSetColumnType(this IConventionPropertyBuilder propertyBuilder, string typeName, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

typeName string

The name of the data type of the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given data type can be set for the property.

CanSetComment(IConventionPropertyBuilder, string, bool)

Returns a value indicating whether the given value can be set as comment for the column.

public static bool CanSetComment(this IConventionPropertyBuilder propertyBuilder, string comment, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

comment string

The comment for the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given value can be set as default for the column.

CanSetComputedColumnSql(IConventionPropertyBuilder, string, bool)

Returns a value indicating whether the given computed value SQL expression can be set for the column.

public static bool CanSetComputedColumnSql(this IConventionPropertyBuilder propertyBuilder, string sql, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

sql string

The SQL expression that computes values for the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given computed value SQL expression can be set for the column.

CanSetDefaultValue(IConventionPropertyBuilder, object, bool)

Returns a value indicating whether the given value can be set as default for the column.

public static bool CanSetDefaultValue(this IConventionPropertyBuilder propertyBuilder, object value, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

value object

The default value of the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given value can be set as default for the column.

CanSetDefaultValueSql(IConventionPropertyBuilder, string, bool)

Returns a value indicating whether the given default value expression can be set for the column.

public static bool CanSetDefaultValueSql(this IConventionPropertyBuilder propertyBuilder, string sql, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

sql string

The SQL expression for the default value of the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given default value expression can be set for the column.

CanSetIsFixedLength(IConventionPropertyBuilder, bool?, bool)

Returns a value indicating whether the property can be configured as being fixed length or not.

public static bool CanSetIsFixedLength(this IConventionPropertyBuilder propertyBuilder, bool? fixedLength, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

fixedLength bool?

A value indicating whether the property is constrained to fixed length values.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the property can be configured as being fixed length or not.

CanSetIsStoredComputedColumn(IConventionPropertyBuilder, bool?, bool)

Returns a value indicating whether the given computed column type can be set for the column.

public static bool CanSetIsStoredComputedColumn(this IConventionPropertyBuilder propertyBuilder, bool? stored, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

stored bool?

If true, the computed value is calculated on row modification and stored in the database like a regular column. If false, the value is computed when the value is read, and does not occupy any actual storage. null selects the database provider default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

bool

true if the given computed column type can be set for the column.

HasColumnName(IConventionPropertyBuilder, string, in StoreObjectIdentifier, bool)

Configures the column that the property maps to in a particular table-like store object.

public static IConventionPropertyBuilder HasColumnName(this IConventionPropertyBuilder propertyBuilder, string name, in StoreObjectIdentifier storeObject, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

name string

The name of the column.

storeObject StoreObjectIdentifier

The identifier of the store object.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionPropertyBuilder

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

HasColumnName(IConventionPropertyBuilder, string, bool)

Configures the column that the property maps to when targeting a relational database.

public static IConventionPropertyBuilder HasColumnName(this IConventionPropertyBuilder propertyBuilder, string name, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

name string

The name of the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionPropertyBuilder

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

HasColumnName(PropertyBuilder, string)

Configures the column that the property maps to when targeting a relational database.

public static PropertyBuilder HasColumnName(this PropertyBuilder propertyBuilder, string name)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

name string

The name of the column.

Returns

PropertyBuilder

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

HasColumnName<TProperty>(PropertyBuilder<TProperty>, string)

Configures the column that the property maps to when targeting a relational database.

public static PropertyBuilder<TProperty> HasColumnName<TProperty>(this PropertyBuilder<TProperty> propertyBuilder, string name)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

name string

The name of the column.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty

The type of the property being configured.

HasColumnType(IConventionPropertyBuilder, string, bool)

Configures the data type of the column that the property maps to when targeting a relational database. This should be the complete type name, including precision, scale, length, etc.

public static IConventionPropertyBuilder HasColumnType(this IConventionPropertyBuilder propertyBuilder, string typeName, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

typeName string

The name of the data type of the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionPropertyBuilder

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

HasColumnType(PropertyBuilder, string)

Configures the data type of the column that the property maps to when targeting a relational database. This should be the complete type name, including precision, scale, length, etc.

public static PropertyBuilder HasColumnType(this PropertyBuilder propertyBuilder, string typeName)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

typeName string

The name of the data type of the column.

Returns

PropertyBuilder

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

HasColumnType<TProperty>(PropertyBuilder<TProperty>, string)

Configures the data type of the column that the property maps to when targeting a relational database. This should be the complete type name, including precision, scale, length, etc.

public static PropertyBuilder<TProperty> HasColumnType<TProperty>(this PropertyBuilder<TProperty> propertyBuilder, string typeName)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

typeName string

The name of the data type of the column.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty

The type of the property being configured.

HasComment(IConventionPropertyBuilder, string, bool)

Configures a comment to be applied to the column

public static IConventionPropertyBuilder HasComment(this IConventionPropertyBuilder propertyBuilder, string comment, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

comment string

The comment for the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionPropertyBuilder

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

HasComment(PropertyBuilder, string)

Configures a comment to be applied to the column

public static PropertyBuilder HasComment(this PropertyBuilder propertyBuilder, string comment)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

comment string

The comment for the column.

Returns

PropertyBuilder

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

HasComment<TProperty>(PropertyBuilder<TProperty>, string)

Configures a comment to be applied to the column

public static PropertyBuilder<TProperty> HasComment<TProperty>(this PropertyBuilder<TProperty> propertyBuilder, string comment)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

comment string

The comment for the column.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty

The type of the property being configured.

HasComputedColumnSql(IConventionPropertyBuilder, string, bool)

Configures the property to map to a computed column when targeting a relational database.

public static IConventionPropertyBuilder HasComputedColumnSql(this IConventionPropertyBuilder propertyBuilder, string sql, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

sql string

The SQL expression that computes values for the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionPropertyBuilder

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

HasComputedColumnSql(PropertyBuilder)

Configures the property to map to a computed column when targeting a relational database.

When called with no arguments, this method tells EF that a column is computed without needing to specify the actual SQL used to computed it. This can be useful when mapping EF to an existing database.

public static PropertyBuilder HasComputedColumnSql(this PropertyBuilder propertyBuilder)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

Returns

PropertyBuilder

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

HasComputedColumnSql(PropertyBuilder, string)

Configures the property to map to a computed column when targeting a relational database.

public static PropertyBuilder HasComputedColumnSql(this PropertyBuilder propertyBuilder, string sql)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

sql string

The SQL expression that computes values for the column.

Returns

PropertyBuilder

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

HasComputedColumnSql(PropertyBuilder, string, bool?)

Configures the property to map to a computed column when targeting a relational database.

public static PropertyBuilder HasComputedColumnSql(this PropertyBuilder propertyBuilder, string sql, bool? stored)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

sql string

The SQL expression that computes values for the column.

stored bool?

If true, the computed value is calculated on row modification and stored in the database like a regular column. If false, the value is computed when the value is read, and does not occupy any actual storage. null selects the database provider default.

Returns

PropertyBuilder

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

HasComputedColumnSql<TProperty>(PropertyBuilder<TProperty>)

Configures the property to map to a computed column when targeting a relational database.

When called with no arguments, this method tells EF that a column is computed without needing to specify the actual SQL used to computed it. This can be useful when mapping EF to an existing database.

public static PropertyBuilder<TProperty> HasComputedColumnSql<TProperty>(this PropertyBuilder<TProperty> propertyBuilder)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty

The type of the property being configured.

HasComputedColumnSql<TProperty>(PropertyBuilder<TProperty>, string)

Configures the property to map to a computed column when targeting a relational database.

public static PropertyBuilder<TProperty> HasComputedColumnSql<TProperty>(this PropertyBuilder<TProperty> propertyBuilder, string sql)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

sql string

The SQL expression that computes values for the column.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty

The type of the property being configured.

HasComputedColumnSql<TProperty>(PropertyBuilder<TProperty>, string, bool?)

Configures the property to map to a computed column when targeting a relational database.

public static PropertyBuilder<TProperty> HasComputedColumnSql<TProperty>(this PropertyBuilder<TProperty> propertyBuilder, string sql, bool? stored)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

sql string

The SQL expression that computes values for the column.

stored bool?

If true, the computed value is calculated on row modification and stored in the database like a regular column. If false, the value is computed when the value is read, and does not occupy any actual storage. null selects the database provider default.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty

The type of the property being configured.

HasDefaultValue(IConventionPropertyBuilder, object, bool)

Configures the default value for the column that the property maps to when targeting a relational database.

public static IConventionPropertyBuilder HasDefaultValue(this IConventionPropertyBuilder propertyBuilder, object value, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

value object

The default value of the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionPropertyBuilder

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

HasDefaultValue(PropertyBuilder)

Configures the default value for the column that the property maps to when targeting a relational database.

When called with no argument, this method tells EF that a column has a default value constraint of some sort without needing to specify exactly what it is. This can be useful when mapping EF to an existing database.

public static PropertyBuilder HasDefaultValue(this PropertyBuilder propertyBuilder)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

Returns

PropertyBuilder

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

HasDefaultValue(PropertyBuilder, object)

Configures the default value for the column that the property maps to when targeting a relational database.

public static PropertyBuilder HasDefaultValue(this PropertyBuilder propertyBuilder, object value)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

value object

The default value of the column.

Returns

PropertyBuilder

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

HasDefaultValueSql(IConventionPropertyBuilder, string, bool)

Configures the default value expression for the column that the property maps to when targeting a relational database.

public static IConventionPropertyBuilder HasDefaultValueSql(this IConventionPropertyBuilder propertyBuilder, string sql, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

sql string

The SQL expression for the default value of the column.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionPropertyBuilder

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

HasDefaultValueSql(PropertyBuilder)

Configures the default value expression for the column that the property maps to when targeting a relational database.

When called with no argument, this method tells EF that a column has a default value constraint of some sort without needing to specify exactly what it is. This can be useful when mapping EF to an existing database.

public static PropertyBuilder HasDefaultValueSql(this PropertyBuilder propertyBuilder)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

Returns

PropertyBuilder

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

HasDefaultValueSql(PropertyBuilder, string)

Configures the default value expression for the column that the property maps to when targeting a relational database.

public static PropertyBuilder HasDefaultValueSql(this PropertyBuilder propertyBuilder, string sql)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

sql string

The SQL expression for the default value of the column.

Returns

PropertyBuilder

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

HasDefaultValueSql<TProperty>(PropertyBuilder<TProperty>)

Configures the default value expression for the column that the property maps to when targeting a relational database.

When called with no argument, this method tells EF that a column has a default value constraint of some sort without needing to specify exactly what it is. This can be useful when mapping EF to an existing database.

public static PropertyBuilder<TProperty> HasDefaultValueSql<TProperty>(this PropertyBuilder<TProperty> propertyBuilder)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty

The type of the property being configured.

HasDefaultValueSql<TProperty>(PropertyBuilder<TProperty>, string)

Configures the default value expression for the column that the property maps to when targeting a relational database.

public static PropertyBuilder<TProperty> HasDefaultValueSql<TProperty>(this PropertyBuilder<TProperty> propertyBuilder, string sql)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

sql string

The SQL expression for the default value of the column.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty

The type of the property being configured.

HasDefaultValue<TProperty>(PropertyBuilder<TProperty>)

Configures the default value for the column that the property maps to when targeting a relational database.

When called with no argument, this method tells EF that a column has a default value constraint of some sort without needing to specify exactly what it is. This can be useful when mapping EF to an existing database.

public static PropertyBuilder<TProperty> HasDefaultValue<TProperty>(this PropertyBuilder<TProperty> propertyBuilder)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty

The type of the property being configured.

HasDefaultValue<TProperty>(PropertyBuilder<TProperty>, object)

Configures the default value for the column that the property maps to when targeting a relational database.

public static PropertyBuilder<TProperty> HasDefaultValue<TProperty>(this PropertyBuilder<TProperty> propertyBuilder, object value)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

value object

The default value of the column.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty

The type of the property being configured.

IsFixedLength(IConventionPropertyBuilder, bool?, bool)

Configures the property as capable of storing only fixed-length data, such as strings.

public static IConventionPropertyBuilder IsFixedLength(this IConventionPropertyBuilder propertyBuilder, bool? fixedLength, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

fixedLength bool?

A value indicating whether the property is constrained to fixed length values.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionPropertyBuilder

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

IsFixedLength(PropertyBuilder, bool)

Configures the property as capable of storing only fixed-length data, such as strings.

public static PropertyBuilder IsFixedLength(this PropertyBuilder propertyBuilder, bool fixedLength = true)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

fixedLength bool

A value indicating whether the property is constrained to fixed length values.

Returns

PropertyBuilder

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

IsFixedLength<TProperty>(PropertyBuilder<TProperty>, bool)

Configures the property as capable of storing only fixed-length data, such as strings.

public static PropertyBuilder<TProperty> IsFixedLength<TProperty>(this PropertyBuilder<TProperty> propertyBuilder, bool fixedLength = true)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

fixedLength bool

A value indicating whether the property is constrained to fixed length values.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty

The type of the property being configured.

IsStoredComputedColumn(IConventionPropertyBuilder, bool?, bool)

Configures the property to map to a computed column of the given type when targeting a relational database.

public static IConventionPropertyBuilder IsStoredComputedColumn(this IConventionPropertyBuilder propertyBuilder, bool? stored, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

stored bool?

If true, the computed value is calculated on row modification and stored in the database like a regular column. If false, the value is computed when the value is read, and does not occupy any actual storage. null selects the database provider default.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionPropertyBuilder

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

UseCollation(IConventionPropertyBuilder, string, bool)

Configures the property to use the given collation. The database column will be be created with the given collation, and it will be used implicitly in all collation-sensitive operations.

public static IConventionPropertyBuilder UseCollation(this IConventionPropertyBuilder propertyBuilder, string collation, bool fromDataAnnotation = false)

Parameters

propertyBuilder IConventionPropertyBuilder

The builder for the property being configured.

collation string

The collation.

fromDataAnnotation bool

Indicates whether the configuration was specified using a data annotation.

Returns

IConventionPropertyBuilder

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

UseCollation(PropertyBuilder, string)

Configures the property to use the given collation. The database column will be be created with the given collation, and it will be used implicitly in all collation-sensitive operations.

public static PropertyBuilder UseCollation(this PropertyBuilder propertyBuilder, string collation)

Parameters

propertyBuilder PropertyBuilder

The builder for the property being configured.

collation string

The collation for the column.

Returns

PropertyBuilder

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

UseCollation<TProperty>(PropertyBuilder<TProperty>, string)

Configures the property to use the given collation. The database column will be be created with the given collation, and it will be used implicitly in all collation-sensitive operations.

public static PropertyBuilder<TProperty> UseCollation<TProperty>(this PropertyBuilder<TProperty> propertyBuilder, string collation)

Parameters

propertyBuilder PropertyBuilder<TProperty>

The builder for the property being configured.

collation string

The collation for the column.

Returns

PropertyBuilder<TProperty>

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

Type Parameters

TProperty