Table of Contents

Class PropertyMappingBuilder<TEntity, TProperty>

Namespace
LinqToDB.Mapping
Assembly
linq2db.dll

Column or association fluent mapping builder.

public class PropertyMappingBuilder<TEntity, TProperty>

Type Parameters

TEntity

Entity type.

TProperty

Column or association member type.

Inheritance
PropertyMappingBuilder<TEntity, TProperty>
Extension Methods

Constructors

PropertyMappingBuilder(EntityMappingBuilder<TEntity>, Expression<Func<TEntity, TProperty>>)

Creates column or association fluent mapping builder.

public PropertyMappingBuilder(EntityMappingBuilder<TEntity> entity, Expression<Func<TEntity, TProperty>> memberGetter)

Parameters

entity EntityMappingBuilder<TEntity>

Entity fluent mapping builder.

memberGetter Expression<Func<TEntity, TProperty>>

Column or association member getter expression.

Methods

Association<TOther>(Expression<Func<TEntity, IEnumerable<TOther>>>, Expression<Func<TEntity, IDataContext, IQueryable<TOther>>>, bool?)

Adds association mapping to current column's entity.

public PropertyMappingBuilder<TEntity, IEnumerable<TOther>> Association<TOther>(Expression<Func<TEntity, IEnumerable<TOther>>> prop, Expression<Func<TEntity, IDataContext, IQueryable<TOther>>> queryExpression, bool? canBeNull = null)

Parameters

prop Expression<Func<TEntity, IEnumerable<TOther>>>

Association member getter expression.

queryExpression Expression<Func<TEntity, IDataContext, IQueryable<TOther>>>

Query expression.

canBeNull bool?

Defines type of join. True - left join, False - inner join.

Returns

PropertyMappingBuilder<TEntity, IEnumerable<TOther>>

Returns fluent property mapping builder.

Type Parameters

TOther

Other association side type

Association<TOther>(Expression<Func<TEntity, IEnumerable<TOther>>>, Expression<Func<TEntity, TOther, bool>>, bool?)

Adds association mapping to current column's entity.

public PropertyMappingBuilder<TEntity, IEnumerable<TOther>> Association<TOther>(Expression<Func<TEntity, IEnumerable<TOther>>> prop, Expression<Func<TEntity, TOther, bool>> predicate, bool? canBeNull = null)

Parameters

prop Expression<Func<TEntity, IEnumerable<TOther>>>

Association member getter expression.

predicate Expression<Func<TEntity, TOther, bool>>

Predicate expression.

canBeNull bool?

Defines type of join. True - left join, False - inner join.

Returns

PropertyMappingBuilder<TEntity, IEnumerable<TOther>>

Returns fluent property mapping builder.

Type Parameters

TOther

Other association side type

Association<TOther>(Expression<Func<TEntity, TOther>>, Expression<Func<TEntity, IDataContext, IQueryable<TOther>>>, bool?)

Adds association mapping to current column's entity.

public PropertyMappingBuilder<TEntity, TOther> Association<TOther>(Expression<Func<TEntity, TOther>> prop, Expression<Func<TEntity, IDataContext, IQueryable<TOther>>> queryExpression, bool? canBeNull = null)

Parameters

prop Expression<Func<TEntity, TOther>>

Association member getter expression.

queryExpression Expression<Func<TEntity, IDataContext, IQueryable<TOther>>>

Query expression.

canBeNull bool?

Defines type of join. True - left join, False - inner join.

Returns

PropertyMappingBuilder<TEntity, TOther>

Returns fluent property mapping builder.

Type Parameters

TOther

Other association side type

Association<TOther>(Expression<Func<TEntity, TOther>>, Expression<Func<TEntity, TOther, bool>>, bool?)

Adds association mapping to current column's entity.

public PropertyMappingBuilder<TEntity, TOther> Association<TOther>(Expression<Func<TEntity, TOther>> prop, Expression<Func<TEntity, TOther, bool>> predicate, bool? canBeNull = null)

Parameters

prop Expression<Func<TEntity, TOther>>

Association member getter expression.

predicate Expression<Func<TEntity, TOther, bool>>

Predicate expression

canBeNull bool?

Defines type of join. True - left join, False - inner join.

Returns

PropertyMappingBuilder<TEntity, TOther>

Returns fluent property mapping builder.

Type Parameters

TOther

Other association side type

Association<TPropElement, TThisKey, TOtherKey>(Expression<Func<TEntity, IEnumerable<TPropElement>>>, Expression<Func<TEntity, TThisKey>>, Expression<Func<TPropElement, TOtherKey>>, bool?)

Adds association mapping to current column's entity.

public PropertyMappingBuilder<TEntity, IEnumerable<TPropElement>> Association<TPropElement, TThisKey, TOtherKey>(Expression<Func<TEntity, IEnumerable<TPropElement>>> prop, Expression<Func<TEntity, TThisKey>> thisKey, Expression<Func<TPropElement, TOtherKey>> otherKey, bool? canBeNull = null)

Parameters

prop Expression<Func<TEntity, IEnumerable<TPropElement>>>

Association member getter expression.

thisKey Expression<Func<TEntity, TThisKey>>

This association key getter expression.

otherKey Expression<Func<TPropElement, TOtherKey>>

Other association key getter expression.

canBeNull bool?

Defines type of join. True - left join, False - inner join.

Returns

PropertyMappingBuilder<TEntity, IEnumerable<TPropElement>>

Returns fluent property mapping builder.

Type Parameters

TPropElement

Association member type.

TThisKey

This association side key type.

TOtherKey

Other association side key type.

Association<TOther, TThisKey, TOtherKey>(Expression<Func<TEntity, TOther>>, Expression<Func<TEntity, TThisKey>>, Expression<Func<TOther, TOtherKey>>, bool?)

Adds association mapping to current column's entity.

public PropertyMappingBuilder<TEntity, TOther> Association<TOther, TThisKey, TOtherKey>(Expression<Func<TEntity, TOther>> prop, Expression<Func<TEntity, TThisKey>> thisKey, Expression<Func<TOther, TOtherKey>> otherKey, bool? canBeNull = null)

Parameters

prop Expression<Func<TEntity, TOther>>

Association member getter expression.

thisKey Expression<Func<TEntity, TThisKey>>

This association key getter expression.

otherKey Expression<Func<TOther, TOtherKey>>

Other association key getter expression.

canBeNull bool?

Defines type of join. True - left join, False - inner join.

Returns

PropertyMappingBuilder<TEntity, TOther>

Returns association mapping builder.

Type Parameters

TOther

Association member type.

TThisKey

This association side key type.

TOtherKey

Other association side key type.

Build()

Adds configured mappings to builder's mapping schema.

public FluentMappingBuilder Build()

Returns

FluentMappingBuilder

Entity<TE>(string?)

Creates entity builder for specified mapping type.

public EntityMappingBuilder<TE> Entity<TE>(string? configuration = null)

Parameters

configuration string

Optional mapping schema configuration name, for which this entity builder should be taken into account. ProviderName for standard configuration names.

Returns

EntityMappingBuilder<TE>

Returns entity mapping builder.

Type Parameters

TE

Mapping type.

HasAttribute(MappingAttribute)

Adds attribute to current mapping member.

public PropertyMappingBuilder<TEntity, TProperty> HasAttribute(MappingAttribute attribute)

Parameters

attribute MappingAttribute

Mapping attribute to add to specified member.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column or association mapping builder.

HasColumnName(string)

Sets name for current column.

public PropertyMappingBuilder<TEntity, TProperty> HasColumnName(string columnName)

Parameters

columnName string

Column name.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

HasConversionFunc<TProvider>(Func<TProperty, TProvider>, Func<TProvider, TProperty>, bool)

Configures the property so that the property value is converted to the given type before writing to the database and converted back when reading from the database.

public PropertyMappingBuilder<TEntity, TProperty> HasConversionFunc<TProvider>(Func<TProperty, TProvider> toProvider, Func<TProvider, TProperty> toModel, bool handlesNulls = false)

Parameters

toProvider Func<TProperty, TProvider>
toModel Func<TProvider, TProperty>
handlesNulls bool

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

Type Parameters

TProvider

The type to convert to and from.

HasConversion<TProvider>(Expression<Func<TProperty, TProvider>>, Expression<Func<TProvider, TProperty>>, bool)

Configures the property so that the property value is converted to the given type before writing to the database and converted back when reading from the database.

public PropertyMappingBuilder<TEntity, TProperty> HasConversion<TProvider>(Expression<Func<TProperty, TProvider>> toProvider, Expression<Func<TProvider, TProperty>> toModel, bool handlesNulls = false)

Parameters

toProvider Expression<Func<TProperty, TProvider>>
toModel Expression<Func<TProvider, TProperty>>
handlesNulls bool

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

Type Parameters

TProvider

The type to convert to and from.

HasCreateFormat(string)

Sets custom column create SQL template.

public PropertyMappingBuilder<TEntity, TProperty> HasCreateFormat(string format)

Parameters

format string

Custom template for column definition in create table SQL expression, generated using CreateTable<T>(IDataContext, string?, string?, string?, string?, string?, DefaultNullable, string?, TableOptions) methods. Template accepts following string parameters:

  • {0} - column name;
  • {1} - column type;
  • {2} - NULL specifier;
  • {3} - identity specification.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

HasDataType(DataType)

Sets LINQ to DB type for current column.

public PropertyMappingBuilder<TEntity, TProperty> HasDataType(DataType dataType)

Parameters

dataType DataType

Data type.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

HasDbType(string)

Sets database type for current column.

public PropertyMappingBuilder<TEntity, TProperty> HasDbType(string dbType)

Parameters

dbType string

Column type.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

HasLength(int)

Sets the length of the database column.

public PropertyMappingBuilder<TEntity, TProperty> HasLength(int length)

Parameters

length int

Column length.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

HasOrder(int)

Sets the Order of the database column.

public PropertyMappingBuilder<TEntity, TProperty> HasOrder(int order)

Parameters

order int

Column order.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

HasPrecision(int)

Sets the precision of the database column.

public PropertyMappingBuilder<TEntity, TProperty> HasPrecision(int precision)

Parameters

precision int

Column precision.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

HasScale(int)

Sets the Scale of the database column.

public PropertyMappingBuilder<TEntity, TProperty> HasScale(int scale)

Parameters

scale int

Column scale.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

HasSkipOnInsert(bool)

Sets whether a column is insertable. This flag will affect only insert operations with implicit columns specification like Insert<T>(IDataContext, T, string?, string?, string?, string?, TableOptions) method and will be ignored when user explicitly specifies value for this column.

public PropertyMappingBuilder<TEntity, TProperty> HasSkipOnInsert(bool skipOnInsert = true)

Parameters

skipOnInsert bool

If true - column will be ignored for implicit insert operations.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

HasSkipOnUpdate(bool)

Sets whether a column is updatable. This flag will affect only update operations with implicit columns specification like Update<T>(IDataContext, T, string?, string?, string?, string?, TableOptions) method and will be ignored when user explicitly specifies value for this column.

public PropertyMappingBuilder<TEntity, TProperty> HasSkipOnUpdate(bool skipOnUpdate = true)

Parameters

skipOnUpdate bool

If true - column will be ignored for implicit update operations.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

HasStorage(string)

Adds data storage property or field for current column.

public PropertyMappingBuilder<TEntity, TProperty> HasStorage(string storage)

Parameters

storage string

Name of storage property or field for current column.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

IsAlias(Expression<Func<TEntity, object>>)

Sets that property is alias to another member.

public PropertyMappingBuilder<TEntity, TProperty> IsAlias(Expression<Func<TEntity, object>> aliasMember)

Parameters

aliasMember Expression<Func<TEntity, object>>

Alias member getter expression.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

IsAlias(string)

Sets that property is alias to another member.

public PropertyMappingBuilder<TEntity, TProperty> IsAlias(string aliasMember)

Parameters

aliasMember string

Alias member name.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

IsColumn()

Sets current member to be included into mapping as column.

public PropertyMappingBuilder<TEntity, TProperty> IsColumn()

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

IsDiscriminator(bool)

Marks current column as discriminator column for inheritance mapping.

public PropertyMappingBuilder<TEntity, TProperty> IsDiscriminator(bool isDiscriminator = true)

Parameters

isDiscriminator bool

If true - column is used as inheritance mapping discriminator.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

IsExpression<TR>(Expression<Func<TEntity, TR>>, bool, string?)

Configure property as alias to another member.

public PropertyMappingBuilder<TEntity, TProperty> IsExpression<TR>(Expression<Func<TEntity, TR>> expression, bool isColumn = false, string? alias = null)

Parameters

expression Expression<Func<TEntity, TR>>

Expression for mapping member during read.

isColumn bool

Indicates whether a property value should be filled during entity materialization (calculated property).

alias string

Optional alias for specific member expression. By default Member Name is used.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

Type Parameters

TR

IsIdentity()

Marks current column as identity column.

public PropertyMappingBuilder<TEntity, TProperty> IsIdentity()

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

IsNotColumn()

Sets current member to be excluded from mapping.

public PropertyMappingBuilder<TEntity, TProperty> IsNotColumn()

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current mapping builder.

IsNotNull()

Sets whether a column can contain NULL values.

public PropertyMappingBuilder<TEntity, TProperty> IsNotNull()

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

IsNullable(bool)

Sets whether a column can contain NULL values.

public PropertyMappingBuilder<TEntity, TProperty> IsNullable(bool isNullable = true)

Parameters

isNullable bool

If true - column could contain NULL values.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

IsPrimaryKey(int)

Marks current column as primary key member.

public PropertyMappingBuilder<TEntity, TProperty> IsPrimaryKey(int order = -1)

Parameters

order int

Order of property in primary key.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

Member<TMember>(Expression<Func<TEntity, TMember>>)

Adds member mapping to current entity.

public PropertyMappingBuilder<TEntity, TMember> Member<TMember>(Expression<Func<TEntity, TMember>> func)

Parameters

func Expression<Func<TEntity, TMember>>

Column mapping property or field getter expression.

Returns

PropertyMappingBuilder<TEntity, TMember>

Returns fluent property mapping builder.

Type Parameters

TMember

Property<TMember>(Expression<Func<TEntity, TMember>>)

Adds new column mapping to current column's entity.

public PropertyMappingBuilder<TEntity, TMember> Property<TMember>(Expression<Func<TEntity, TMember>> func)

Parameters

func Expression<Func<TEntity, TMember>>

Column mapping property or field getter expression.

Returns

PropertyMappingBuilder<TEntity, TMember>

Returns property mapping builder.

Type Parameters

TMember

SkipOnEntityFetch(bool)

Marks current column to be skipped by default during a full entity fetch

public PropertyMappingBuilder<TEntity, TProperty> SkipOnEntityFetch(bool skipOnEntityFetch = true)

Parameters

skipOnEntityFetch bool

If true, column won't be fetched unless explicity selected in a Linq query.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.

UseSequence(string, string?, string?)

Specifies value generation sequence for current column. See SequenceNameAttribute notes for list of supported databases.

public PropertyMappingBuilder<TEntity, TProperty> UseSequence(string sequenceName, string? schema = null, string? configuration = null)

Parameters

sequenceName string

Name of sequence.

schema string

Optional sequence schema name.

configuration string

Optional mapping configuration name. If not specified, entity configuration used.

Returns

PropertyMappingBuilder<TEntity, TProperty>

Returns current column mapping builder.