Interface IMutableModel
- 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 IMutableModel : IReadOnlyModel, IMutableAnnotatable, IReadOnlyAnnotatable
- Inherited Members
- Extension Methods
Remarks
This interface is used during model creation and allows the metadata to be modified. Once the model is built, IModel represents a read-only view of the same metadata.
See Modeling entity types and relationships for more information and examples.
Methods
AddEntityType(string)
Adds an entity type of default type to the model.
IMutableEntityType AddEntityType(string name)
Parameters
name
stringThe name of the entity to be added.
Returns
- IMutableEntityType
The new entity type.
Remarks
Shadow entities are not currently supported in a model that is used at runtime with a DbContext. Therefore, shadow state entity types will only exist in migration model snapshots, etc.
AddEntityType(string, string, IMutableEntityType)
Adds an owned entity type with a defining navigation to the model.
IMutableEntityType AddEntityType(string name, string definingNavigationName, IMutableEntityType definingEntityType)
Parameters
name
stringThe name of the entity type to be added.
definingNavigationName
stringThe defining navigation.
definingEntityType
IMutableEntityTypeThe defining entity type.
Returns
- IMutableEntityType
The new entity type.
AddEntityType(string, Type)
Adds a shared type entity type to the model.
IMutableEntityType AddEntityType(string name, Type type)
Parameters
name
stringThe name of the entity to be added.
type
TypeThe CLR class that is used to represent instances of the entity type.
Returns
- IMutableEntityType
The new entity type.
Remarks
Shared type entity type is an entity type which can share CLR type with other types in the model but has a unique name and always identified by the name.
AddEntityType(Type)
Adds an entity type to the model.
IMutableEntityType AddEntityType(Type type)
Parameters
type
TypeThe CLR class that is used to represent instances of the entity type.
Returns
- IMutableEntityType
The new entity type.
AddEntityType(Type, string, IMutableEntityType)
Adds an owned entity type with a defining navigation to the model.
IMutableEntityType AddEntityType(Type type, string definingNavigationName, IMutableEntityType definingEntityType)
Parameters
type
TypeThe CLR class that is used to represent instances of this entity type.
definingNavigationName
stringThe defining navigation.
definingEntityType
IMutableEntityTypeThe defining entity type.
Returns
- IMutableEntityType
The new entity type.
AddIgnored(string)
Marks the given entity type name as ignored, preventing conventions from adding a matching entity type to the model.
string AddIgnored(string typeName)
Parameters
typeName
stringThe name of the entity type to be ignored.
Returns
- string
The name of the ignored type.
AddIgnored(Type)
Marks the given entity type as ignored, preventing conventions from adding a matching entity type to the model.
string AddIgnored(Type type)
Parameters
type
TypeThe entity type to be ignored.
Returns
- string
The name of the ignored type.
AddOwned(Type)
Marks the given entity type as owned, indicating that when discovered matching entity types should be configured as owned.
void AddOwned(Type type)
Parameters
type
TypeThe type of the entity type that should be owned.
AddOwnedEntityType(string)
Adds an owned entity type of default type to the model.
IMutableEntityType AddOwnedEntityType(string name)
Parameters
name
stringThe name of the entity to be added.
Returns
- IMutableEntityType
The new entity type.
Remarks
Shadow entities are not currently supported in a model that is used at runtime with a DbContext. Therefore, shadow state entity types will only exist in migration model snapshots, etc.
AddOwnedEntityType(string, Type)
Adds an owned shared type entity type to the model.
IMutableEntityType AddOwnedEntityType(string name, Type type)
Parameters
name
stringThe name of the entity to be added.
type
TypeThe CLR class that is used to represent instances of the entity type.
Returns
- IMutableEntityType
The new entity type.
Remarks
Shared type entity type is an entity type which can share CLR type with other types in the model but has a unique name and always identified by the name.
AddOwnedEntityType(Type)
Adds an owned entity type to the model.
IMutableEntityType AddOwnedEntityType(Type type)
Parameters
type
TypeThe CLR class that is used to represent instances of the entity type.
Returns
- IMutableEntityType
The new entity type.
AddShared(Type)
Marks the given entity type as shared, indicating that when discovered matching entity types should be configured as shared type entity type.
void AddShared(Type type)
Parameters
type
TypeThe type of the entity type that should be shared.
DelayConventions()
Prevents conventions from being executed immediately when a metadata aspect is modified. All the delayed conventions will be executed after the returned object is disposed.
IConventionBatch DelayConventions()
Returns
- IConventionBatch
An object that should be disposed to execute the delayed conventions.
Remarks
This is useful when performing multiple operations that depend on each other.
FinalizeModel()
Forces post-processing on the model such that it is ready for use by the runtime. This post- processing happens automatically when using OnModelCreating(ModelBuilder); this method allows it to be run explicitly in cases where the automatic execution is not possible.
IModel FinalizeModel()
Returns
- IModel
The finalized model.
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.
IMutableEntityType? FindEntityType(string name)
Parameters
name
stringThe name of the entity type to find.
Returns
- IMutableEntityType
The entity type, or null if none is found.
FindEntityType(string, string, IMutableEntityType)
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.
IMutableEntityType? FindEntityType(string name, string definingNavigationName, IMutableEntityType definingEntityType)
Parameters
name
stringThe name of the entity type to find.
definingNavigationName
stringThe defining navigation of the entity type to find.
definingEntityType
IMutableEntityTypeThe defining entity type of the entity type to find.
Returns
- IMutableEntityType
The entity type, or null if none is found.
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.
IMutableEntityType? FindEntityType(Type type)
Parameters
type
TypeThe type to find the corresponding entity type for.
Returns
- IMutableEntityType
The entity type, or null if none is found.
FindEntityType(Type, string, IMutableEntityType)
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.
IMutableEntityType? FindEntityType(Type type, string definingNavigationName, IMutableEntityType definingEntityType)
Parameters
type
TypeThe type of the entity type to find.
definingNavigationName
stringThe defining navigation of the entity type to find.
definingEntityType
IMutableEntityTypeThe defining entity type of the entity type to find.
Returns
- IMutableEntityType
The entity type, or null if none is found.
FindEntityTypes(Type)
Gets the entity types matching the given type.
IEnumerable<IMutableEntityType> FindEntityTypes(Type type)
Parameters
type
TypeThe type of the entity type to find.
Returns
- IEnumerable<IMutableEntityType>
The entity types found.
FindLeastDerivedEntityTypes(Type, Func<IReadOnlyEntityType, bool>?)
Returns the entity types corresponding to the least derived types from the given one.
IEnumerable<IMutableEntityType> FindLeastDerivedEntityTypes(Type type, Func<IReadOnlyEntityType, bool>? condition = null)
Parameters
type
TypeThe base type.
condition
Func<IReadOnlyEntityType, bool>An optional condition for filtering entity types.
Returns
- IEnumerable<IMutableEntityType>
List of entity types corresponding to the least derived types from the given one.
GetEntityTypes()
Gets all entity types defined in the model.
IEnumerable<IMutableEntityType> GetEntityTypes()
Returns
- IEnumerable<IMutableEntityType>
All entity types defined in the model.
IsIgnored(string)
Indicates whether the given entity type name is ignored.
bool IsIgnored(string typeName)
Parameters
typeName
stringThe name of the entity type that might be ignored.
Returns
IsIgnored(Type)
Indicates whether the given entity type name is ignored.
bool IsIgnored(Type type)
Parameters
type
TypeThe entity type that might be ignored.
Returns
IsOwned(Type)
Returns a value indicating whether the entity types using the given type should be configured as owned types when discovered by conventions.
bool IsOwned(Type type)
Parameters
type
TypeThe type of the entity type that might be owned.
Returns
RemoveEntityType(IMutableEntityType)
Removes an entity type from the model.
IMutableEntityType? RemoveEntityType(IMutableEntityType entityType)
Parameters
entityType
IMutableEntityTypeThe entity type to be removed.
Returns
- IMutableEntityType
The removed entity type, or null if the entity type was not found.
RemoveEntityType(string)
Removes an entity type without a defining navigation from the model.
IMutableEntityType? RemoveEntityType(string name)
Parameters
name
stringThe name of the entity type to be removed.
Returns
- IMutableEntityType
The entity type that was removed.
RemoveEntityType(string, string, IMutableEntityType)
Removes an entity type with the given type, defining navigation name and the defining entity type
IMutableEntityType? RemoveEntityType(string name, string definingNavigationName, IMutableEntityType definingEntityType)
Parameters
name
stringThe name of the entity type to be removed.
definingNavigationName
stringThe defining navigation.
definingEntityType
IMutableEntityTypeThe defining entity type.
Returns
- IMutableEntityType
The entity type that was removed.
RemoveEntityType(Type)
Removes an entity type from the model.
IMutableEntityType? RemoveEntityType(Type type)
Parameters
type
TypeThe entity type to be removed.
Returns
- IMutableEntityType
The entity type that was removed.
RemoveEntityType(Type, string, IMutableEntityType)
Removes an entity type with the given type, defining navigation name and the defining entity type
IMutableEntityType? RemoveEntityType(Type type, string definingNavigationName, IMutableEntityType definingEntityType)
Parameters
type
TypeThe CLR class that is used to represent instances of this entity type.
definingNavigationName
stringThe defining navigation.
definingEntityType
IMutableEntityTypeThe defining entity type.
Returns
- IMutableEntityType
The entity type that was removed.
RemoveIgnored(string)
Removes the ignored entity type name.
string? RemoveIgnored(string typeName)
Parameters
typeName
stringThe name of the ignored entity type to be removed.
Returns
- string
The removed ignored type name.
RemoveIgnored(Type)
Removes the ignored entity type.
string? RemoveIgnored(Type type)
Parameters
type
TypeThe ignored entity type to be removed.
Returns
- string
The name of the removed ignored type.
RemoveOwned(Type)
Removes the given owned type, indicating that when discovered matching entity types should not be configured as owned.
string? RemoveOwned(Type type)
Parameters
type
TypeThe type of the entity type that should not be owned.
Returns
- string
The name of the removed owned type.
RemoveShared(Type)
Marks the given type as not shared, indicating that when discovered matching entity types should not be configured as shared type entity types.
Type? RemoveShared(Type type)
Parameters
type
TypeThe type of the entity type that should be shared.
Returns
- Type
The removed type.
SetChangeTrackingStrategy(ChangeTrackingStrategy?)
Sets the default change tracking strategy to use for entities in the model. This strategy indicates how the context detects changes to properties for an instance of an entity type.
void SetChangeTrackingStrategy(ChangeTrackingStrategy? changeTrackingStrategy)
Parameters
changeTrackingStrategy
ChangeTrackingStrategy?The strategy to use.
SetPropertyAccessMode(PropertyAccessMode?)
Sets the PropertyAccessMode to use for properties of all entity types in this model.
void SetPropertyAccessMode(PropertyAccessMode? propertyAccessMode)
Parameters
propertyAccessMode
PropertyAccessMode?The PropertyAccessMode, or null to clear the mode set.
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 set here will be used for any property for which no override has been specified.