Interface IConventionModelBuilder
- Namespace
- Microsoft.EntityFrameworkCore.Metadata.Builders
- Assembly
- Microsoft.EntityFrameworkCore.dll
Provides a simple API surface for configuring an IConventionModelBuilder from conventions.
This interface is typically used by database providers (and other extensions). It is generally not used in application code.
public interface IConventionModelBuilder : IConventionAnnotatableBuilder
- Inherited Members
Remarks
See Model building conventions for more information and examples.
Properties
Metadata
Gets the model being configured.
IConventionModel Metadata { get; }
Property Value
Methods
CanHaveEntity(string, bool)
Returns a value indicating whether the given entity type can be added to the model.
bool CanHaveEntity(string name, bool fromDataAnnotation = false)
Parameters
name
stringThe name of the entity type.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanHaveEntity(Type, bool)
Returns a value indicating whether the given entity type can be added to the model.
bool CanHaveEntity(Type type, bool fromDataAnnotation = false)
Parameters
type
TypeThe type of the entity type.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanHaveSharedTypeEntity(string, Type?, bool)
Returns a value indicating whether the given entity type can be added to the model.
bool CanHaveSharedTypeEntity(string name, Type? type, bool fromDataAnnotation = false)
Parameters
name
stringThe name of the entity type.
type
TypeThe type of the entity type.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanIgnore(string, bool)
Returns a value indicating whether the given entity type name can be ignored from the current configuration source
bool CanIgnore(string typeName, bool fromDataAnnotation = false)
Parameters
typeName
stringThe entity type name to be removed from the model.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanIgnore(Type, bool)
Returns a value indicating whether the given entity type can be ignored from the current configuration source.
bool CanIgnore(Type type, bool fromDataAnnotation = false)
Parameters
type
TypeThe entity type to be removed from the model.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanRemoveEntity(IConventionEntityType, bool)
Returns a value indicating whether the entity type can be removed from the model.
bool CanRemoveEntity(IConventionEntityType entityType, bool fromDataAnnotation = false)
Parameters
entityType
IConventionEntityTypeThe entity type to be removed.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetChangeTrackingStrategy(ChangeTrackingStrategy?, bool)
Returns a value indicating whether the given change tracking strategy can be set from the current configuration source
bool CanSetChangeTrackingStrategy(ChangeTrackingStrategy? changeTrackingStrategy, bool fromDataAnnotation = false)
Parameters
changeTrackingStrategy
ChangeTrackingStrategy?The change tracking strategy to be used.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
CanSetPropertyAccessMode(PropertyAccessMode?, bool)
Returns a value indicating whether the given property access mode can be set from the current configuration source
bool CanSetPropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false)
Parameters
propertyAccessMode
PropertyAccessMode?The PropertyAccessMode to use for properties of this model.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
ComplexType(Type, bool)
Marks a type as complex. All references to this type will be configured as complex properties.
IConventionModelBuilder? ComplexType(Type type, bool fromDataAnnotation = false)
Parameters
type
TypeThe type to be configured.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
An IConventionModelBuilder to continue configuration if the annotation was set, null otherwise.
Entity(string, bool?, bool)
Returns an object that can be used to configure a given entity type in the model. If an entity type with the provided name is not already part of the model, a new shadow entity type will be added to the model.
IConventionEntityTypeBuilder? Entity(string name, bool? shouldBeOwned = false, bool fromDataAnnotation = false)
Parameters
name
stringThe name of the entity type to be configured.
shouldBeOwned
bool?true if the entity type should be owned, false if the entity type should not be owned
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionEntityTypeBuilder
An object that can be used to configure the entity type if the entity type was added or already part of the model, null otherwise.
Entity(string, string, IConventionEntityType, bool)
Returns an object that can be used to configure a given entity type with defining navigation. If an entity type with the provided name is not already part of the model, a new shadow entity type will be added to the model.
IConventionEntityTypeBuilder? Entity(string name, string definingNavigationName, IConventionEntityType definingEntityType, bool fromDataAnnotation = false)
Parameters
name
stringThe name of the entity type to be configured.
definingNavigationName
stringThe defining navigation.
definingEntityType
IConventionEntityTypeThe defining entity type.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionEntityTypeBuilder
An object that can be used to configure the entity type if the entity type was added or already part of the model, null otherwise.
Entity(Type, bool?, bool)
Returns an object that can be used to configure a given entity type in the model. If an entity type with the provided type is not already part of the model, a new entity type will be added to the model.
IConventionEntityTypeBuilder? Entity(Type type, bool? shouldBeOwned = false, bool fromDataAnnotation = false)
Parameters
type
TypeThe type of the entity type to be configured.
shouldBeOwned
bool?true if the entity type should be owned, false if the entity type should not be owned
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionEntityTypeBuilder
An object that can be used to configure the entity type if the entity type was added or already part of the model, null otherwise.
Entity(Type, string, IConventionEntityType, bool)
Returns an object that can be used to configure a given entity type with defining navigation. If an entity type with the provided type is not already part of the model, a new entity type will be added to the model.
IConventionEntityTypeBuilder? Entity(Type type, string definingNavigationName, IConventionEntityType definingEntityType, bool fromDataAnnotation = false)
Parameters
type
TypeThe type of the entity type to be configured.
definingNavigationName
stringThe defining navigation.
definingEntityType
IConventionEntityTypeThe defining entity type.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionEntityTypeBuilder
An object that can be used to configure the entity type if the entity type was added or already part of the model, null otherwise.
HasAnnotation(string, object?, bool)
Sets the annotation stored under the given name. Overwrites the existing annotation if an annotation with the specified name already exists with same or lower ConfigurationSource.
IConventionModelBuilder? HasAnnotation(string name, object? value, bool fromDataAnnotation = false)
Parameters
name
stringThe name of the annotation to be set.
value
objectThe value to be stored in the annotation.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
An IConventionModelBuilder to continue configuration if the annotation was set, null otherwise.
HasChangeTrackingStrategy(ChangeTrackingStrategy?, bool)
Configures the default ChangeTrackingStrategy to be used for this model. This strategy indicates how the context detects changes to properties for an instance of an entity type.
IConventionModelBuilder? HasChangeTrackingStrategy(ChangeTrackingStrategy? changeTrackingStrategy, bool fromDataAnnotation = false)
Parameters
changeTrackingStrategy
ChangeTrackingStrategy?The change tracking strategy to be used.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
The same builder instance if the configuration was successful, null otherwise.
HasNoAnnotation(string, bool)
Removes the annotation with the given name from this object.
IConventionModelBuilder? HasNoAnnotation(string name, bool fromDataAnnotation = false)
Parameters
name
stringThe name of the annotation to remove.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
An IConventionModelBuilder to continue configuration if the annotation was set, null otherwise.
HasNoEntityType(IConventionEntityType, bool)
Removes the given entity type from the model.
IConventionModelBuilder? HasNoEntityType(IConventionEntityType entityType, bool fromDataAnnotation = false)
Parameters
entityType
IConventionEntityTypeThe entity type to be removed from the model.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
The same builder instance if the given entity type was removed, null otherwise.
HasNonNullAnnotation(string, object?, bool)
Sets the annotation stored under the given name. Overwrites the existing annotation if an annotation with the specified name already exists with same or lower ConfigurationSource. Removes the annotation if null value is specified.
IConventionModelBuilder? HasNonNullAnnotation(string name, object? value, bool fromDataAnnotation = false)
Parameters
name
stringThe name of the annotation to be set.
value
objectThe value to be stored in the annotation. null to remove the annotations.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
An IConventionModelBuilder to continue configuration if the annotation was set or removed, null otherwise.
Ignore(string, bool)
Excludes the given entity type name from the model and prevents it from being added by convention.
IConventionModelBuilder? Ignore(string typeName, bool fromDataAnnotation = false)
Parameters
typeName
stringThe entity type name to be removed from the model.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
true if the given entity type name was ignored.
Ignore(Type, bool)
Excludes the given entity type from the model and prevents it from being added by convention.
IConventionModelBuilder? Ignore(Type type, bool fromDataAnnotation = false)
Parameters
type
TypeThe entity type to be removed from the model.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
The same builder instance so that additional configuration calls can be chained if the given entity type was ignored, null otherwise.
IsIgnored(string, bool)
Indicates whether the given entity type name is ignored for the current configuration source.
bool IsIgnored(string typeName, bool fromDataAnnotation = false)
Parameters
typeName
stringThe name of the entity type that might be ignored.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
IsIgnored(Type, bool)
Indicates whether the given entity type name is ignored for the current configuration source.
bool IsIgnored(Type type, bool fromDataAnnotation = false)
Parameters
type
TypeThe name of the entity type that might be ignored.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
Owned(Type, bool)
Marks an entity type as owned. All references to this type will be configured as separate owned type instances.
IConventionOwnedEntityTypeBuilder? Owned(Type type, bool fromDataAnnotation = false)
Parameters
type
TypeThe entity type to be configured.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionOwnedEntityTypeBuilder
An object that can be used to provide default configuration for the owned entity types.
SharedTypeEntity(string, Type, bool?, bool)
Returns an object that can be used to configure a given shared type entity type in the model.
IConventionEntityTypeBuilder? SharedTypeEntity(string name, Type type, bool? shouldBeOwned = false, bool fromDataAnnotation = false)
Parameters
name
stringThe name of the entity type to be configured.
type
TypeThe type of the entity type to be configured.
shouldBeOwned
bool?true if the entity type should be owned, false if the entity type should not be owned
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionEntityTypeBuilder
An object that can be used to configure the entity type if the entity type was added or already part of the model, null otherwise.
Remarks
If an entity type with the provided name is not already part of the model, a new entity type with provided CLR type will be added to the model as shared type entity type.
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.
UsePropertyAccessMode(PropertyAccessMode?, bool)
Sets the PropertyAccessMode to use for all properties of this entity type.
IConventionModelBuilder? UsePropertyAccessMode(PropertyAccessMode? propertyAccessMode, bool fromDataAnnotation = false)
Parameters
propertyAccessMode
PropertyAccessMode?The PropertyAccessMode to use for properties of this model.
fromDataAnnotation
boolIndicates whether the configuration was specified using a data annotation.
Returns
- IConventionModelBuilder
The same builder instance if the configuration was successful, null otherwise.
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 in the model as described in the PropertyAccessMode enum.