Class RelationalModelValidator
- Namespace
- Microsoft.EntityFrameworkCore.Infrastructure
- Assembly
- Microsoft.EntityFrameworkCore.Relational.dll
The validator that enforces rules common for all relational providers.
public class RelationalModelValidator : ModelValidator
- Inheritance
-
RelationalModelValidator
Remarks
The service lifetime is Singleton. This means a single instance is used by many Microsoft.EntityFrameworkCore.DbContext instances. The implementation must be thread-safe. This service cannot depend on services registered as Scoped.
See Implementation of database providers and extensions for more information and examples.
Constructors
RelationalModelValidator(ModelValidatorDependencies, RelationalModelValidatorDependencies)
Creates a new instance of RelationalModelValidator.
public RelationalModelValidator(ModelValidatorDependencies dependencies, RelationalModelValidatorDependencies relationalDependencies)
Parameters
dependencies
ModelValidatorDependenciesParameter object containing dependencies for this service.
relationalDependencies
RelationalModelValidatorDependenciesParameter object containing relational dependencies for this service.
Properties
RelationalDependencies
Relational provider-specific dependencies for this service.
protected virtual RelationalModelValidatorDependencies RelationalDependencies { get; }
Property Value
Methods
GetDefaultColumnValue(IProperty, in StoreObjectIdentifier)
Returns the object that is used as the default value for the column the property is mapped to.
protected virtual object? GetDefaultColumnValue(IProperty property, in StoreObjectIdentifier storeObject)
Parameters
property
IPropertyThe property to get the default value for.
storeObject
StoreObjectIdentifierThe identifier of the store object.
Returns
- object
The object that is used as the default value for the column the property is mapped to.
IsRedundant(IForeignKey)
protected override bool IsRedundant(IForeignKey foreignKey)
Parameters
foreignKey
IForeignKey
Returns
ThrowPropertyNotMappedException(string, IConventionEntityType, IConventionProperty)
Throws an InvalidOperationException with a message containing provider-specific information, when available, indicating possible reasons why the property cannot be mapped.
protected override void ThrowPropertyNotMappedException(string propertyType, IConventionEntityType entityType, IConventionProperty unmappedProperty)
Parameters
propertyType
stringThe property CLR type.
entityType
IConventionEntityTypeThe entity type.
unmappedProperty
IConventionPropertyThe property.
Validate(IModel, IDiagnosticsLogger<Validation>)
Validates a model, throwing an exception if any errors are found.
public override void Validate(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateBoolsWithDefaults(IModel, IDiagnosticsLogger<Validation>)
Validates the mapping/configuration of bool properties in the model.
protected virtual void ValidateBoolsWithDefaults(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateCompatible(ICheckConstraint, ICheckConstraint, string, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of two check constraints with the same name.
protected virtual void ValidateCompatible(ICheckConstraint checkConstraint, ICheckConstraint duplicateCheckConstraint, string indexName, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
checkConstraint
ICheckConstraintA check constraint.
duplicateCheckConstraint
ICheckConstraintAnother check constraint.
indexName
stringThe name of the check constraint.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateCompatible(IForeignKey, IForeignKey, string, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of two foreign keys mapped to the same foreign key constraint.
protected virtual void ValidateCompatible(IForeignKey foreignKey, IForeignKey duplicateForeignKey, string foreignKeyName, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
foreignKey
IForeignKeyA foreign key.
duplicateForeignKey
IForeignKeyAnother foreign key.
foreignKeyName
stringThe foreign key constraint name.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateCompatible(IIndex, IIndex, string, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of two indexes mapped to the same table index.
protected virtual void ValidateCompatible(IIndex index, IIndex duplicateIndex, string indexName, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
index
IIndexAn index.
duplicateIndex
IIndexAnother index.
indexName
stringThe name of the index.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateCompatible(IKey, IKey, string, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of two keys mapped to the same unique constraint.
protected virtual void ValidateCompatible(IKey key, IKey duplicateKey, string keyName, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
key
IKeyA key.
duplicateKey
IKeyAnother key.
keyName
stringThe name of the unique constraint.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateCompatible(IProperty, IProperty, string, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of two properties mapped to the same column.
protected virtual void ValidateCompatible(IProperty property, IProperty duplicateProperty, string columnName, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
property
IPropertyA property.
duplicateProperty
IPropertyAnother property.
columnName
stringThe column name.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateCompatible(ITrigger, ITrigger, string, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of two trigger with the same name.
protected virtual void ValidateCompatible(ITrigger trigger, ITrigger duplicateTrigger, string indexName, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
trigger
ITriggerA trigger.
duplicateTrigger
ITriggerAnother trigger.
indexName
stringThe name of the trigger.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateDbFunctions(IModel, IDiagnosticsLogger<Validation>)
Validates the mapping/configuration of functions in the model.
protected virtual void ValidateDbFunctions(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateDefaultValuesOnKeys(IModel, IDiagnosticsLogger<Validation>)
Validates the mapping/configuration of default values in the model.
protected virtual void ValidateDefaultValuesOnKeys(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateIndexProperties(IModel, IDiagnosticsLogger<Validation>)
Validates that the properties of any one index are all mapped to columns on at least one common table.
protected virtual void ValidateIndexProperties(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateInheritanceMapping(IModel, IDiagnosticsLogger<Validation>)
Validates the mapping/configuration of inheritance in the model.
protected override void ValidateInheritanceMapping(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateJsonEntities(IModel, IDiagnosticsLogger<Validation>)
Validates the JSON entities.
protected virtual void ValidateJsonEntities(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateJsonEntityKey(in StoreObjectIdentifier, IEntityType)
Validate the key of entity mapped to a JSON column.
protected virtual void ValidateJsonEntityKey(in StoreObjectIdentifier storeObject, IEntityType jsonEntityType)
Parameters
storeObject
StoreObjectIdentifierThe store object.
jsonEntityType
IEntityTypeThe entity type containing the key to validate.
ValidateJsonEntityNavigations(in StoreObjectIdentifier, IEntityType)
Validates navigations of the entity mapped to a JSON column.
protected virtual void ValidateJsonEntityNavigations(in StoreObjectIdentifier storeObject, IEntityType jsonEntityType)
Parameters
storeObject
StoreObjectIdentifierThe store object.
jsonEntityType
IEntityTypeThe entity type to validate.
ValidateJsonEntityProperties(in StoreObjectIdentifier, IEntityType)
Validate the properties of entity mapped to a JSON column.
protected virtual void ValidateJsonEntityProperties(in StoreObjectIdentifier storeObject, IEntityType jsonEntityType)
Parameters
storeObject
StoreObjectIdentifierThe store object.
jsonEntityType
IEntityTypeThe entity type containing the properties to validate.
ValidateJsonEntityRoot(in StoreObjectIdentifier, IEntityType)
Validates the root entity mapped to a JSON column.
protected virtual void ValidateJsonEntityRoot(in StoreObjectIdentifier storeObject, IEntityType rootType)
Parameters
storeObject
StoreObjectIdentifierThe store object.
rootType
IEntityTypeThe entity type to validate.
ValidateMappingFragments(IModel, IDiagnosticsLogger<Validation>)
Validates the entity type mapping fragments.
protected virtual void ValidateMappingFragments(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateMappingStrategy(IEntityType, string?)
Validates that the given mapping strategy is supported
protected virtual void ValidateMappingStrategy(IEntityType entityType, string? mappingStrategy)
Parameters
entityType
IEntityTypeThe entity type.
mappingStrategy
stringThe mapping strategy.
ValidateNoMutableKeys(IModel, IDiagnosticsLogger<Validation>)
Validates the mapping/configuration of mutable in the model.
protected override void ValidateNoMutableKeys(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidatePropertyOverrides(IModel, IDiagnosticsLogger<Validation>)
Validates the table-specific property overrides.
protected virtual void ValidatePropertyOverrides(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateSharedCheckConstraintCompatibility(IReadOnlyList<IEntityType>, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of check constraints in a given shared table.
protected virtual void ValidateSharedCheckConstraintCompatibility(IReadOnlyList<IEntityType> mappedTypes, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
mappedTypes
IReadOnlyList<IEntityType>The mapped entity types.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateSharedColumnsCompatibility(IReadOnlyList<IEntityType>, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of properties sharing columns in a given table-like object.
protected virtual void ValidateSharedColumnsCompatibility(IReadOnlyList<IEntityType> mappedTypes, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
mappedTypes
IReadOnlyList<IEntityType>The mapped entity types.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateSharedForeignKeysCompatibility(IReadOnlyList<IEntityType>, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of foreign keys in a given shared table.
protected virtual void ValidateSharedForeignKeysCompatibility(IReadOnlyList<IEntityType> mappedTypes, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
mappedTypes
IReadOnlyList<IEntityType>The mapped entity types.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateSharedIndexesCompatibility(IReadOnlyList<IEntityType>, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of indexes in a given shared table.
protected virtual void ValidateSharedIndexesCompatibility(IReadOnlyList<IEntityType> mappedTypes, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
mappedTypes
IReadOnlyList<IEntityType>The mapped entity types.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateSharedKeysCompatibility(IReadOnlyList<IEntityType>, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of primary and alternate keys in a given shared table.
protected virtual void ValidateSharedKeysCompatibility(IReadOnlyList<IEntityType> mappedTypes, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
mappedTypes
IReadOnlyList<IEntityType>The mapped entity types.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateSharedTableCompatibility(IModel, IDiagnosticsLogger<Validation>)
Validates the mapping/configuration of shared tables in the model.
protected virtual void ValidateSharedTableCompatibility(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateSharedTableCompatibility(IReadOnlyList<IEntityType>, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of entity types sharing a given table.
protected virtual void ValidateSharedTableCompatibility(IReadOnlyList<IEntityType> mappedTypes, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
mappedTypes
IReadOnlyList<IEntityType>The mapped entity types.
storeObject
StoreObjectIdentifierThe table identifier.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateSharedTriggerCompatibility(IReadOnlyList<IEntityType>, in StoreObjectIdentifier, IDiagnosticsLogger<Validation>)
Validates the compatibility of triggers in a given shared table.
protected virtual void ValidateSharedTriggerCompatibility(IReadOnlyList<IEntityType> mappedTypes, in StoreObjectIdentifier storeObject, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
mappedTypes
IReadOnlyList<IEntityType>The mapped entity types.
storeObject
StoreObjectIdentifierThe identifier of the store object.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateSharedViewCompatibility(IModel, IDiagnosticsLogger<Validation>)
Validates the mapping/configuration of shared views in the model.
protected virtual void ValidateSharedViewCompatibility(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateSharedViewCompatibility(IReadOnlyList<IEntityType>, string, string?, IDiagnosticsLogger<Validation>)
Validates the compatibility of entity types sharing a given view.
protected virtual void ValidateSharedViewCompatibility(IReadOnlyList<IEntityType> mappedTypes, string viewName, string? schema, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
mappedTypes
IReadOnlyList<IEntityType>The mapped entity types.
viewName
stringThe view name.
schema
stringThe schema.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateSqlQueries(IModel, IDiagnosticsLogger<Validation>)
Validates the mapping/configuration of SQL queries in the model.
protected virtual void ValidateSqlQueries(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateStoredProcedures(IModel, IDiagnosticsLogger<Validation>)
Validates the mapping/configuration of stored procedures in the model.
protected virtual void ValidateStoredProcedures(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateTriggers(IModel, IDiagnosticsLogger<Validation>)
Validates that the triggers are unambiguously mapped to exactly one table.
protected override void ValidateTriggers(IModel model, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
model
IModelThe model to validate.
logger
IDiagnosticsLogger<Validation>The logger to use.
ValidateValueGeneration(IEntityType, IKey, IDiagnosticsLogger<Validation>)
Validates the key value generation is valid.
protected virtual void ValidateValueGeneration(IEntityType entityType, IKey key, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
Parameters
entityType
IEntityTypeThe entity type.
key
IKeyThe key.
logger
IDiagnosticsLogger<Validation>The logger to use.