Table of Contents

Class RuntimeModel

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

Metadata about the shape of entities, the relationships between them, and how they map to the database. A model is typically created by overriding the OnModelCreating(ModelBuilder) method on a derived DbContext.

public class RuntimeModel : AnnotatableBase, IRuntimeModel, IModel, IReadOnlyModel, IAnnotatable, IReadOnlyAnnotatable
Inheritance
RuntimeModel
Implements
Inherited Members
Extension Methods

Remarks

This is a light-weight implementation that is constructed from a built model and is not meant to be used at design-time.

The service lifetime is Scoped. This means that each DbContext instance will use its own instance of this service. The implementation may depend on other services registered with any lifetime. The implementation does not need to be thread-safe.

See Modeling entity types and relationships for more information and examples.

Constructors

RuntimeModel()

public RuntimeModel()

Properties

DebugView

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 virtual DebugView DebugView { get; }

Property Value

DebugView

ModelId

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 virtual Guid ModelId { get; set; }

Property Value

Guid

Methods

AddEntityType(string, Type, RuntimeEntityType?, bool, string?, ChangeTrackingStrategy, PropertyInfo?, bool, object?)

Adds an entity type with a defining navigation to the model.

public virtual RuntimeEntityType AddEntityType(string name, Type type, RuntimeEntityType? baseType = null, bool sharedClrType = false, string? discriminatorProperty = null, ChangeTrackingStrategy changeTrackingStrategy = ChangeTrackingStrategy.Snapshot, PropertyInfo? indexerPropertyInfo = null, bool propertyBag = false, object? discriminatorValue = null)

Parameters

name string

The name of the entity type to be added.

type Type

The CLR class that is used to represent instances of this type.

baseType RuntimeEntityType

The base type of this entity type.

sharedClrType bool

Whether this entity type can share its ClrType with other entities.

discriminatorProperty string

The name of the property that will be used for storing a discriminator value.

changeTrackingStrategy ChangeTrackingStrategy

The change tracking strategy for this entity type.

indexerPropertyInfo PropertyInfo

The PropertyInfo for the indexer on the associated CLR type if one exists.

propertyBag bool

A value indicating whether this entity type has an indexer which is able to contain arbitrary properties and a method that can be used to determine whether a given indexer property contains a value.

discriminatorValue object

The discriminator value for this entity type.

Returns

RuntimeEntityType

The new entity type.

AddTypeMappingConfiguration(Type, int?, bool?, int?, int?, Type?, ValueConverter?)

Adds configuration for a scalar type.

public virtual RuntimeTypeMappingConfiguration AddTypeMappingConfiguration(Type clrType, int? maxLength = null, bool? unicode = null, int? precision = null, int? scale = null, Type? providerPropertyType = null, ValueConverter? valueConverter = null)

Parameters

clrType Type

The type of value the property will hold.

maxLength int?

The maximum length of data that is allowed in this property type.

unicode bool?

A value indicating whether or not the property can persist Unicode characters.

precision int?

The precision of data that is allowed in this property type.

scale int?

The scale of data that is allowed in this property type.

providerPropertyType Type

The type that the property value will be converted to before being sent to the database provider.

valueConverter ValueConverter

The custom ValueConverter for this type.

Returns

RuntimeTypeMappingConfiguration

The newly created property.

FindAdHocEntityType(Type)

Gets the entity type with the given name. Returns null if no entity type with the given name has been mapped as an ad-hoc type.

public virtual RuntimeEntityType? FindAdHocEntityType(Type clrType)

Parameters

clrType Type

The CLR type of the entity type to find.

Returns

RuntimeEntityType

The entity type, or null if none is found.

FindEntityType(string)

Gets the entity type with the given name. Returns null if no entity type with the given name is found or the given CLR type is being used by shared type entity type or the entity type has a defining navigation.

public virtual RuntimeEntityType? FindEntityType(string name)

Parameters

name string

The name of the entity type to find.

Returns

RuntimeEntityType

The entity type, or null if none is found.

GetAdHocEntityTypes()

Gets all ad-hoc entity types defined in the model.

public virtual IEnumerable<IReadOnlyEntityType> GetAdHocEntityTypes()

Returns

IEnumerable<IReadOnlyEntityType>

All entity types defined in the model.

Remarks

See Modeling entity types and relationships for more information and examples.

GetOrAddAdHocEntityType(RuntimeEntityType)

Adds an ad-hoc entity type to the model.

public virtual RuntimeEntityType GetOrAddAdHocEntityType(RuntimeEntityType entityType)

Parameters

entityType RuntimeEntityType

The entity type.

Returns

RuntimeEntityType

SetSkipDetectChanges(bool)

Sets a value indicating whether DetectChanges() should be called.

public virtual void SetSkipDetectChanges(bool skipDetectChanges)

Parameters

skipDetectChanges bool