Table of Contents

Interface IReadOnlyModel

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 IReadOnlyModel : IReadOnlyAnnotatable
Inherited Members

Remarks

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

Properties

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

Property Value

Guid

Methods

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.

IReadOnlyEntityType? FindEntityType(string name)

Parameters

name string

The name of the entity type to find.

Returns

IReadOnlyEntityType

The entity type, or null if none is found.

Remarks

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

FindEntityType(string, string, IReadOnlyEntityType)

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

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

Parameters

name string

The name of the entity type to find.

definingNavigationName string

The defining navigation of the entity type to find.

definingEntityType IReadOnlyEntityType

The defining entity type of the entity type to find.

Returns

IReadOnlyEntityType

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.

IReadOnlyEntityType? FindEntityType(Type type)

Parameters

type Type

The type to find the corresponding entity type for.

Returns

IReadOnlyEntityType

The entity type, or null if none is found.

Remarks

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

FindEntityType(Type, string, IReadOnlyEntityType)

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

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

Parameters

type Type

The type of the entity type to find.

definingNavigationName string

The defining navigation of the entity type to find.

definingEntityType IReadOnlyEntityType

The defining entity type of the entity type to find.

Returns

IReadOnlyEntityType

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<IReadOnlyEntityType> FindEntityTypes(Type type)

Parameters

type Type

The type of the entity type to find.

Returns

IEnumerable<IReadOnlyEntityType>

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<IReadOnlyEntityType> 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<IReadOnlyEntityType>

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.

GetChangeTrackingStrategy()

Gets the default change tracking strategy being used for entities in the model. This strategy indicates how the context detects changes to properties for an instance of an entity type.

ChangeTrackingStrategy GetChangeTrackingStrategy()

Returns

ChangeTrackingStrategy

The change tracking strategy.

Remarks

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

GetEntityTypes()

Gets all entity types defined in the model.

IEnumerable<IReadOnlyEntityType> GetEntityTypes()

Returns

IEnumerable<IReadOnlyEntityType>

All entity types defined in the model.

Remarks

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

GetProductVersion()

Gets the EF Core assembly version used to build this model.

string? GetProductVersion()

Returns

string

Remarks

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

GetPropertyAccessMode()

Gets the PropertyAccessMode being used for properties of entity types in this model.

PropertyAccessMode GetPropertyAccessMode()

Returns

PropertyAccessMode

The access mode being used.

Remarks

Note that individual entity types can override this access mode, and individual properties of entity types can override the access mode set on the entity type. The value returned here will be used for any property for which no override has been specified.

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

IsShared(Type)

Gets a value indicating whether the CLR type is used by shared type entities in the model.

bool IsShared(Type type)

Parameters

type Type

The CLR type.

Returns

bool

Whether the CLR type is used by shared type entities in the model.

Remarks

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

ToDebugString(MetadataDebugStringOptions, int)

Creates a human-readable representation of the given metadata.

Warning: Do not rely on the format of the returned string. It is designed for debugging only and may change arbitrarily between releases.

string ToDebugString(MetadataDebugStringOptions options = MetadataDebugStringOptions.ShortDefault, int indent = 0)

Parameters

options MetadataDebugStringOptions

Options for generating the string.

indent int

The number of indent spaces to use before each new line.

Returns

string

A human-readable representation.

Remarks

See Modeling entity types and relationships and EF Core debug views for more information and examples.