Table of Contents

Class ComplexPropertyBuilder<TComplex>

Namespace
Microsoft.EntityFrameworkCore.Metadata.Builders
Assembly
Microsoft.EntityFrameworkCore.dll

Provides a simple API for configuring an IMutableEntityType.

public class ComplexPropertyBuilder<TComplex> : ComplexPropertyBuilder, IInfrastructure<IConventionComplexPropertyBuilder>, IInfrastructure<IConventionComplexTypeBuilder>

Type Parameters

TComplex

The complex type being configured.

Inheritance
ComplexPropertyBuilder<TComplex>
Implements
Inherited Members

Remarks

Instances of this class are returned from methods when using the ModelBuilder API and it is not designed to be directly constructed in your application code.

Constructors

ComplexPropertyBuilder(IMutableComplexProperty)

This is an internal API that supports the Entity Framework Core infrastructure and not subject to the same compatibility standards as public APIs. It may be changed or removed without notice in any release. You should only use it directly in your code with extreme caution and knowing that doing so can result in application failures when updating to a new Entity Framework Core release.

[EntityFrameworkInternal]
public ComplexPropertyBuilder(IMutableComplexProperty complexProperty)

Parameters

complexProperty IMutableComplexProperty

Methods

ComplexProperty(string, Action<ComplexPropertyBuilder>)

Configures a complex property of the complex type. If no property with the given name exists, then a new property will be added.

public virtual ComplexPropertyBuilder<TComplex> ComplexProperty(string propertyName, Action<ComplexPropertyBuilder> buildAction)

Parameters

propertyName string

The name of the property to be configured.

buildAction Action<ComplexPropertyBuilder>

An action that performs configuration of the property.

Returns

ComplexPropertyBuilder<TComplex>

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

Remarks

When adding a new property with this overload the property name must match the name of a CLR property or field on the complex type. This overload cannot be used to add a new shadow state complex property.

ComplexProperty(Type, string, Action<ComplexPropertyBuilder>)

Configures a complex property of the complex type. If no property with the given name exists, then a new property will be added.

public virtual ComplexPropertyBuilder<TComplex> ComplexProperty(Type propertyType, string propertyName, Action<ComplexPropertyBuilder> buildAction)

Parameters

propertyType Type

The type of the property to be configured.

propertyName string

The name of the property to be configured.

buildAction Action<ComplexPropertyBuilder>

An action that performs configuration of the property.

Returns

ComplexPropertyBuilder<TComplex>

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

Remarks

When adding a new complex property, if a property with the same name exists in the complex class then it will be added to the model. If no property exists in the complex class, then a new shadow state complex property will be added. A shadow state property is one that does not have a corresponding property in the complex class. The current value for the property is stored in the ChangeTracker rather than being stored in instances of the complex class.

ComplexProperty(Type, string, string, Action<ComplexPropertyBuilder>)

Configures a complex property of the complex type. If no property with the given name exists, then a new property will be added.

public virtual ComplexPropertyBuilder<TComplex> ComplexProperty(Type propertyType, string propertyName, string complexTypeName, Action<ComplexPropertyBuilder> buildAction)

Parameters

propertyType Type

The type of the property to be configured.

propertyName string

The name of the property to be configured.

complexTypeName string

The name of the complex type.

buildAction Action<ComplexPropertyBuilder>

An action that performs configuration of the property.

Returns

ComplexPropertyBuilder<TComplex>

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

Remarks

When adding a new complex property, if a property with the same name exists in the complex class then it will be added to the model. If no property exists in the complex class, then a new shadow state complex property will be added. A shadow state property is one that does not have a corresponding property in the complex class. The current value for the property is stored in the ChangeTracker rather than being stored in instances of the complex class.

ComplexProperty<TProperty>(Expression<Func<TComplex, TProperty>>)

Returns an object that can be used to configure a complex property of the complex type. If no property with the given name exists, then a new property will be added.

public virtual ComplexPropertyBuilder<TProperty> ComplexProperty<TProperty>(Expression<Func<TComplex, TProperty>> propertyExpression)

Parameters

propertyExpression Expression<Func<TComplex, TProperty>>

A lambda expression representing the property to be configured ( blog => blog.Url).

Returns

ComplexPropertyBuilder<TProperty>

An object that can be used to configure the property.

Type Parameters

TProperty

The type of the property to be configured.

Remarks

When adding a new property, if a property with the same name exists in the complex class then it will be added to the model. If no property exists in the complex class, then a new shadow state complex property will be added. A shadow state property is one that does not have a corresponding property in the complex class. The current value for the property is stored in the ChangeTracker rather than being stored in instances of the complex class.

ComplexProperty<TProperty>(Expression<Func<TComplex, TProperty>>, Action<ComplexPropertyBuilder<TProperty>>)

Configures a complex property of the complex type. If no property with the given name exists, then a new property will be added.

public virtual ComplexPropertyBuilder<TComplex> ComplexProperty<TProperty>(Expression<Func<TComplex, TProperty>> propertyExpression, Action<ComplexPropertyBuilder<TProperty>> buildAction)

Parameters

propertyExpression Expression<Func<TComplex, TProperty>>

A lambda expression representing the property to be configured ( blog => blog.Url).

buildAction Action<ComplexPropertyBuilder<TProperty>>

An action that performs configuration of the property.

Returns

ComplexPropertyBuilder<TComplex>

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

Type Parameters

TProperty

The type of the property to be configured.

Remarks

When adding a new property, if a property with the same name exists in the complex class then it will be added to the model. If no property exists in the complex class, then a new shadow state complex property will be added. A shadow state property is one that does not have a corresponding property in the complex class. The current value for the property is stored in the ChangeTracker rather than being stored in instances of the complex class.

ComplexProperty<TProperty>(Expression<Func<TComplex, TProperty>>, string)

Returns an object that can be used to configure a complex property of the complex type. If no property with the given name exists, then a new property will be added.

public virtual ComplexPropertyBuilder<TProperty> ComplexProperty<TProperty>(Expression<Func<TComplex, TProperty>> propertyExpression, string complexTypeName)

Parameters

propertyExpression Expression<Func<TComplex, TProperty>>

A lambda expression representing the property to be configured ( blog => blog.Url).

complexTypeName string

The name of the complex type.

Returns

ComplexPropertyBuilder<TProperty>

An object that can be used to configure the property.

Type Parameters

TProperty

The type of the property to be configured.

Remarks

When adding a new property, if a property with the same name exists in the complex class then it will be added to the model. If no property exists in the complex class, then a new shadow state complex property will be added. A shadow state property is one that does not have a corresponding property in the complex class. The current value for the property is stored in the ChangeTracker rather than being stored in instances of the complex class.

ComplexProperty<TProperty>(Expression<Func<TComplex, TProperty>>, string, Action<ComplexPropertyBuilder<TProperty>>)

Configures a complex property of the complex type. If no property with the given name exists, then a new property will be added.

public virtual ComplexPropertyBuilder<TComplex> ComplexProperty<TProperty>(Expression<Func<TComplex, TProperty>> propertyExpression, string complexTypeName, Action<ComplexPropertyBuilder<TProperty>> buildAction)

Parameters

propertyExpression Expression<Func<TComplex, TProperty>>

A lambda expression representing the property to be configured ( blog => blog.Url).

complexTypeName string

The name of the complex type.

buildAction Action<ComplexPropertyBuilder<TProperty>>

An action that performs configuration of the property.

Returns

ComplexPropertyBuilder<TComplex>

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

Type Parameters

TProperty

The type of the property to be configured.

Remarks

When adding a new property, if a property with the same name exists in the complex class then it will be added to the model. If no property exists in the complex class, then a new shadow state complex property will be added. A shadow state property is one that does not have a corresponding property in the complex class. The current value for the property is stored in the ChangeTracker rather than being stored in instances of the complex class.

ComplexProperty<TProperty>(string, Action<ComplexPropertyBuilder<TProperty>>)

Configures a complex property of the complex type. If no property with the given name exists, then a new property will be added.

public virtual ComplexPropertyBuilder<TComplex> ComplexProperty<TProperty>(string propertyName, Action<ComplexPropertyBuilder<TProperty>> buildAction)

Parameters

propertyName string

The name of the property to be configured.

buildAction Action<ComplexPropertyBuilder<TProperty>>

An action that performs configuration of the property.

Returns

ComplexPropertyBuilder<TComplex>

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

Type Parameters

TProperty

The type of the property to be configured.

Remarks

When adding a new property, if a property with the same name exists in the complex class then it will be added to the model. If no property exists in the complex class, then a new shadow state complex property will be added. A shadow state property is one that does not have a corresponding property in the complex class. The current value for the property is stored in the ChangeTracker rather than being stored in instances of the complex class.

ComplexProperty<TProperty>(string, string, Action<ComplexPropertyBuilder<TProperty>>)

Configures a complex property of the complex type. If no property with the given name exists, then a new property will be added.

public virtual ComplexPropertyBuilder<TComplex> ComplexProperty<TProperty>(string propertyName, string complexTypeName, Action<ComplexPropertyBuilder<TProperty>> buildAction)

Parameters

propertyName string

The name of the property to be configured.

complexTypeName string

The name of the complex type.

buildAction Action<ComplexPropertyBuilder<TProperty>>

An action that performs configuration of the property.

Returns

ComplexPropertyBuilder<TComplex>

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

Type Parameters

TProperty

The type of the property to be configured.

Remarks

When adding a new property, if a property with the same name exists in the complex class then it will be added to the model. If no property exists in the complex class, then a new shadow state complex property will be added. A shadow state property is one that does not have a corresponding property in the complex class. The current value for the property is stored in the ChangeTracker rather than being stored in instances of the complex class.

HasChangeTrackingStrategy(ChangeTrackingStrategy)

Configures the ChangeTrackingStrategy to be used for this entity type. This strategy indicates how the context detects changes to properties for an instance of the entity type.

public virtual ComplexPropertyBuilder<TComplex> HasChangeTrackingStrategy(ChangeTrackingStrategy changeTrackingStrategy)

Parameters

changeTrackingStrategy ChangeTrackingStrategy

The change tracking strategy to be used.

Returns

ComplexPropertyBuilder<TComplex>

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

HasField(string)

Sets the backing field to use for this property.

public virtual ComplexPropertyBuilder<TComplex> HasField(string fieldName)

Parameters

fieldName string

The field name.

Returns

ComplexPropertyBuilder<TComplex>

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

Remarks

Backing fields are normally found by convention. This method is useful for setting backing fields explicitly in cases where the correct field is not found by convention.

By default, the backing field, if one is found or has been specified, is used when new objects are constructed, typically when entities are queried from the database. Properties are used for all other accesses. This can be changed by calling UsePropertyAccessMode(PropertyAccessMode).

See Backing fields for more information and examples.

HasPropertyAnnotation(string, object?)

Adds or updates an annotation on the entity type. If an annotation with the key specified in annotation already exists its value will be updated.

public virtual ComplexPropertyBuilder<TComplex> HasPropertyAnnotation(string annotation, object? value)

Parameters

annotation string

The key of the annotation to be added or updated.

value object

The value to be stored in the annotation.

Returns

ComplexPropertyBuilder<TComplex>

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

HasTypeAnnotation(string, object?)

Adds or updates an annotation on the entity type. If an annotation with the key specified in annotation already exists its value will be updated.

public virtual ComplexPropertyBuilder<TComplex> HasTypeAnnotation(string annotation, object? value)

Parameters

annotation string

The key of the annotation to be added or updated.

value object

The value to be stored in the annotation.

Returns

ComplexPropertyBuilder<TComplex>

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

Ignore(Expression<Func<TComplex, object?>>)

Excludes the given property from the entity type. This method is typically used to remove properties or navigations from the entity type that were added by convention.

public virtual ComplexPropertyBuilder<TComplex> Ignore(Expression<Func<TComplex, object?>> propertyExpression)

Parameters

propertyExpression Expression<Func<TComplex, object>>

A lambda expression representing the property to be ignored (blog => blog.Url).

Returns

ComplexPropertyBuilder<TComplex>

Ignore(string)

Excludes the given property from the entity type. This method is typically used to remove properties or navigations from the entity type that were added by convention.

public virtual ComplexPropertyBuilder<TComplex> Ignore(string propertyName)

Parameters

propertyName string

The name of the property to be removed from the entity type.

Returns

ComplexPropertyBuilder<TComplex>

IsRequired(bool)

Configures whether this property must have a value assigned or null is a valid value. A property can only be configured as non-required if it is based on a CLR type that can be assigned null.

public virtual ComplexPropertyBuilder<TComplex> IsRequired(bool required = true)

Parameters

required bool

A value indicating whether the property is required.

Returns

ComplexPropertyBuilder<TComplex>

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

PrimitiveCollection<TProperty>(Expression<Func<TComplex, TProperty>>)

Returns an object that can be used to configure a primitive collection property of the entity type. If the specified property is not already part of the model, it will be added.

public virtual ComplexTypePrimitiveCollectionBuilder<TProperty> PrimitiveCollection<TProperty>(Expression<Func<TComplex, TProperty>> propertyExpression)

Parameters

propertyExpression Expression<Func<TComplex, TProperty>>

A lambda expression representing the property to be configured ( blog => blog.Url).

Returns

ComplexTypePrimitiveCollectionBuilder<TProperty>

An object that can be used to configure the property.

Type Parameters

TProperty

Property<TProperty>(Expression<Func<TComplex, TProperty>>)

Returns an object that can be used to configure a property of the entity type. If the specified property is not already part of the model, it will be added.

public virtual ComplexTypePropertyBuilder<TProperty> Property<TProperty>(Expression<Func<TComplex, TProperty>> propertyExpression)

Parameters

propertyExpression Expression<Func<TComplex, TProperty>>

A lambda expression representing the property to be configured ( blog => blog.Url).

Returns

ComplexTypePropertyBuilder<TProperty>

An object that can be used to configure the property.

Type Parameters

TProperty

UseDefaultPropertyAccessMode(PropertyAccessMode)

Sets the PropertyAccessMode to use for all properties of this entity type.

public virtual ComplexPropertyBuilder<TComplex> UseDefaultPropertyAccessMode(PropertyAccessMode propertyAccessMode)

Parameters

propertyAccessMode PropertyAccessMode

The PropertyAccessMode to use for properties of this entity type.

Returns

ComplexPropertyBuilder<TComplex>

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

Remarks

By default, the backing field, if one is found by convention or has been specified, is used when new objects are constructed, typically when entities are queried from the database. Properties are used for all other accesses. Calling this method will change that behavior for all properties of this entity type as described in the PropertyAccessMode enum.

Calling this method overrides for all properties of this entity type any access mode that was set on the model.

UsePropertyAccessMode(PropertyAccessMode)

Sets the PropertyAccessMode to use for this property.

public virtual ComplexPropertyBuilder<TComplex> UsePropertyAccessMode(PropertyAccessMode propertyAccessMode)

Parameters

propertyAccessMode PropertyAccessMode

The PropertyAccessMode to use for this property.

Returns

ComplexPropertyBuilder<TComplex>

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

Remarks

By default, the backing field, if one is found by convention or has been specified, is used when new objects are constructed, typically when entities are queried from the database. Properties are used for all other accesses. Calling this method will change that behavior for this property as described in the PropertyAccessMode enum.

Calling this method overrides for this property any access mode that was set on the entity type or model.