Class EntityPropertyBuilder<T>
Fluent builder for a single property mapping, returned by Property(Expression<Func<T, object>>).
public class EntityPropertyBuilder<T>
Type Parameters
T
- Inheritance
-
EntityPropertyBuilder<T>
- Inherited Members
- Extension Methods
Constructors
EntityPropertyBuilder(Expression<Func<T, object>>)
Creates a builder for the property selected by propertySelector.
public EntityPropertyBuilder(Expression<Func<T, object>> propertySelector)
Parameters
propertySelectorExpression<Func<T, object>>Selects the property to map; the expression must produce a PropertyInfo.
Methods
Build()
Resolves the selected property's PropertyInfo and produces its mapping metadata.
public IPropertyMetadata Build()
Returns
- IPropertyMetadata
The property's mapping metadata.
Exceptions
- InvalidOperationException
The selector does not produce a PropertyInfo, the converter's model type does not match the property type, the dynamic-columns store has an invalid type, or DecimalPrecision(int, int) was declared with a bound provider type that is not decimal (a converter to text or a JSON column) or as a partial pair.
- ArgumentOutOfRangeException
DecimalPrecision(int, int) declared a precision or scale outside its allowed range (precision 1..38, scale 0..precision).
Collation(string)
Declares the provider-native collation of the selected property's column. It is applied to the
column in collation-sensitive query operations (comparison, LIKE, ORDER BY,
GROUP BY) on a provider that supports a per-expression COLLATE clause
(SupportsCollation).
public EntityPropertyBuilder<T> Collation(string collation)
Parameters
collationstringThe provider-native collation name.
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
Computed()
Marks the selected property as a database-generated computed column that can never be written. The insert builders exclude it from the written values.
public EntityPropertyBuilder<T> Computed()
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
DecimalPrecision(int, int)
Declares the decimal precision and scale of the selected property. The pair is read by DecimalPrecision/DecimalScale and used where a provider needs the declared precision/scale (for example the column metadata of a table-valued parameter). The pair is only recorded here; it is validated by Build() against the type actually bound for the column (precision 1..38, scale 0..precision, and a bound provider type of decimal).
public EntityPropertyBuilder<T> DecimalPrecision(int precision, int scale)
Parameters
precisionintThe total number of decimal digits (1 to 38).
scaleintThe number of digits to the right of the decimal point (0 to
precision).
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
Duration(DurationUnit, int)
Declares the unit in which a TimeSpan property is stored on a provider
without a native duration type. Providers with a native type (PostgreSQL interval,
MySQL/MariaDB TIME) ignore the unit.
public EntityPropertyBuilder<T> Duration(DurationUnit unit, int precision = 0)
Parameters
unitDurationUnitThe storage unit of the integer value.
precisionintThe fractional-second precision of the native type; zero for the provider default.
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
DynamicColumnsStore()
Marks the selected property as the entity's dynamic-columns store: it receives the row's unmapped columns when the entity is read instead of mapping to a column itself. The property must have a setter and be assignable from Dictionary<TKey, TValue> with string keys and object values. Cannot be combined with a column name, a value/JSON converter or RangeColumns(string, string, bool, bool).
public EntityPropertyBuilder<T> DynamicColumnsStore()
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
HasColumnName(string)
Sets the column name the selected property maps to.
public EntityPropertyBuilder<T> HasColumnName(string columnName)
Parameters
columnNamestringThe target column name.
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
HasConversion(IPropertyValueConverter)
Declares the value converter that maps the selected property between its CLR type and the provider representation. Cannot be combined with RangeColumns(string, string, bool, bool).
public EntityPropertyBuilder<T> HasConversion(IPropertyValueConverter converter)
Parameters
converterIPropertyValueConverterThe converter to apply; must produce the property's CLR type on read.
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
Exceptions
- InvalidOperationException
The property is already mapped with RangeColumns(string, string, bool, bool).
HasConversion<TModel, TProvider>(ValueConverter<TModel, TProvider>)
Declares a strongly typed value converter for the selected property. Cannot be combined with RangeColumns(string, string, bool, bool).
public EntityPropertyBuilder<T> HasConversion<TModel, TProvider>(ValueConverter<TModel, TProvider> converter)
Parameters
converterValueConverter<TModel, TProvider>The converter to apply.
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
Type Parameters
TModelThe CLR model type of the property.
TProviderThe provider-side representation.
Exceptions
- InvalidOperationException
The property is already mapped with RangeColumns(string, string, bool, bool).
HasConversion<TModel, TProvider>(Expression<Func<TModel, TProvider>>, Expression<Func<TProvider, TModel>>)
Declares a value converter from a pair of conversion expressions instead of a converter class. Cannot be combined with RangeColumns(string, string, bool, bool).
public EntityPropertyBuilder<T> HasConversion<TModel, TProvider>(Expression<Func<TModel, TProvider>> toProvider, Expression<Func<TProvider, TModel>> fromProvider)
Parameters
toProviderExpression<Func<TModel, TProvider>>Converts a model value to the provider representation.
fromProviderExpression<Func<TProvider, TModel>>Converts a provider value back to the model representation.
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
Type Parameters
TModelThe CLR model type of the property.
TProviderThe provider-side representation.
Exceptions
- InvalidOperationException
The property is already mapped with RangeColumns(string, string, bool, bool).
Identity()
Marks the selected property as database-generated (an identity/auto-increment column). The insert builders exclude it from the written values.
public EntityPropertyBuilder<T> Identity()
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
JsonColumn(Action<JsonColumnOptions>?)
Declares the selected property as stored in a JSON column and serialized with
System.Text.Json. Cannot be combined with
RangeColumns(string, string, bool, bool).
public EntityPropertyBuilder<T> JsonColumn(Action<JsonColumnOptions>? configure = null)
Parameters
configureAction<JsonColumnOptions>Configures the storage form and serializer options, or null for the defaults.
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
Exceptions
- InvalidOperationException
The property is already mapped with RangeColumns(string, string, bool, bool).
Key()
Marks the selected property as (part of) the entity key. The DML builders use the key to
address a row; declaring it here avoids the Id/<TypeName>Id convention.
public EntityPropertyBuilder<T> Key()
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
RangeColumns(string, string, bool, bool)
Declares that the selected Range<T> property is stored as a pair of scalar columns on a provider without a native range type. Mutually exclusive with HasConversion(IPropertyValueConverter) and JsonColumn(Action<JsonColumnOptions>?): whichever is configured first is retained and the other call fails.
public EntityPropertyBuilder<T> RangeColumns(string lowerColumn, string upperColumn, bool lowerInclusive = true, bool upperInclusive = false)
Parameters
lowerColumnstringThe column that stores the lower bound.
upperColumnstringThe column that stores the upper bound.
lowerInclusiveboolWhether the lower bound is part of the range.
upperInclusiveboolWhether the upper bound is part of the range.
Returns
- EntityPropertyBuilder<T>
This builder, for chaining.
Exceptions
- InvalidOperationException
The property is already mapped with HasConversion(IPropertyValueConverter) or JsonColumn(Action<JsonColumnOptions>?).