Table of Contents

Interface IModel

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 interface IModel : IReadOnlyModel, IAnnotatable, IReadOnlyAnnotatable
Inherited Members
Extension Methods

Remarks

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.

Properties

ModelDependencies

The runtime service dependencies.

RuntimeModelDependencies? ModelDependencies { get; set; }

Property Value

RuntimeModelDependencies

Methods

FindEntityType(string)

Gets the entity 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.

IEntityType? FindEntityType(string name)

Parameters

name string

The name of the entity type to find.

Returns

IEntityType

The entity type, or null if none is found.

Remarks

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

FindEntityType(string, string, IEntityType)

Gets the entity type for the given name, defining navigation name and the defining entity type. Returns null if no matching entity type is found.

IEntityType? FindEntityType(string name, string definingNavigationName, IEntityType definingEntityType)

Parameters

name string

The name of the entity type to find.

definingNavigationName string

The defining navigation of the entity type to find.

definingEntityType IEntityType

The defining entity type of the entity type to find.

Returns

IEntityType

The entity type, or null if none is found.

Remarks

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

FindEntityType(Type)

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

IEntityType? FindEntityType(Type type)

Parameters

type Type

The type to find the corresponding entity type for.

Returns

IEntityType

The entity type, or null if none is found.

Remarks

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

FindEntityType(Type, string, IEntityType)

Gets the entity type for the given name, defining navigation name and the defining entity type. Returns null if no matching entity type is found.

IEntityType? FindEntityType(Type type, string definingNavigationName, IEntityType definingEntityType)

Parameters

type Type

The type of the entity type to find.

definingNavigationName string

The defining navigation of the entity type to find.

definingEntityType IEntityType

The defining entity type of the entity type to find.

Returns

IEntityType

The entity type, or null if none is found.

Remarks

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

FindEntityTypes(Type)

Gets the entity types matching the given type.

IEnumerable<IEntityType> FindEntityTypes(Type type)

Parameters

type Type

The type of the entity type to find.

Returns

IEnumerable<IEntityType>

The entity types found.

Remarks

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

FindLeastDerivedEntityTypes(Type, Func<IReadOnlyEntityType, bool>?)

Returns the entity types corresponding to the least derived types from the given.

IEnumerable<IEntityType> FindLeastDerivedEntityTypes(Type type, Func<IReadOnlyEntityType, bool>? condition = null)

Parameters

type Type

The base type.

condition Func<IReadOnlyEntityType, bool>

An optional condition for filtering entity types.

Returns

IEnumerable<IEntityType>

List of entity types corresponding to the least derived types from the given.

Remarks

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

FindRuntimeEntityType(Type?)

Gets the entity that maps the given entity class, where the class may be a proxy derived from the actual entity type. Returns null if no entity type with the given CLR type is found or the given CLR type is being used by shared type entity type or the entity type has a defining navigation.

IEntityType? FindRuntimeEntityType(Type? type)

Parameters

type Type

The type to find the corresponding entity type for.

Returns

IEntityType

The entity type, or null if none is found.

Remarks

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

FindTypeMappingConfiguration(Type)

Finds the pre-convention configuration for a given scalar Type.

ITypeMappingConfiguration? FindTypeMappingConfiguration(Type scalarType)

Parameters

scalarType Type

The CLR type.

Returns

ITypeMappingConfiguration

The pre-convention configuration or null if none is found.

Remarks

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

GetEntityTypes()

Gets all entity types defined in the model.

IEnumerable<IEntityType> GetEntityTypes()

Returns

IEnumerable<IEntityType>

All entity types defined in the model.

Remarks

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

GetModelDependencies()

Gets the runtime service dependencies.

RuntimeModelDependencies GetModelDependencies()

Returns

RuntimeModelDependencies

GetTypeMappingConfigurations()

Gets all the pre-convention configurations.

IEnumerable<ITypeMappingConfiguration> GetTypeMappingConfigurations()

Returns

IEnumerable<ITypeMappingConfiguration>

The pre-convention configurations.

Remarks

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

IsIndexerMethod(MethodInfo)

Gets a value indicating whether the given MethodInfo represents an indexer access.

bool IsIndexerMethod(MethodInfo methodInfo)

Parameters

methodInfo MethodInfo

The MethodInfo to check.

Returns

bool

Remarks

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