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
dependenciesModelValidatorDependenciesParameter object containing dependencies for this service.
relationalDependenciesRelationalModelValidatorDependenciesParameter 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
propertyIPropertyThe property to get the default value for.
storeObjectStoreObjectIdentifierThe 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
foreignKeyIForeignKey
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
propertyTypestringThe property CLR type.
entityTypeIConventionEntityTypeThe entity type.
unmappedPropertyIConventionPropertyThe 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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
checkConstraintICheckConstraintA check constraint.
duplicateCheckConstraintICheckConstraintAnother check constraint.
indexNamestringThe name of the check constraint.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
foreignKeyIForeignKeyA foreign key.
duplicateForeignKeyIForeignKeyAnother foreign key.
foreignKeyNamestringThe foreign key constraint name.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
indexIIndexAn index.
duplicateIndexIIndexAnother index.
indexNamestringThe name of the index.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
keyIKeyA key.
duplicateKeyIKeyAnother key.
keyNamestringThe name of the unique constraint.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
propertyIPropertyA property.
duplicatePropertyIPropertyAnother property.
columnNamestringThe column name.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
triggerITriggerA trigger.
duplicateTriggerITriggerAnother trigger.
indexNamestringThe name of the trigger.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
storeObjectStoreObjectIdentifierThe store object.
jsonEntityTypeIEntityTypeThe 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
storeObjectStoreObjectIdentifierThe store object.
jsonEntityTypeIEntityTypeThe 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
storeObjectStoreObjectIdentifierThe store object.
jsonEntityTypeIEntityTypeThe 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
storeObjectStoreObjectIdentifierThe store object.
rootTypeIEntityTypeThe 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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
entityTypeIEntityTypeThe entity type.
mappingStrategystringThe 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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
mappedTypesIReadOnlyList<IEntityType>The mapped entity types.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
mappedTypesIReadOnlyList<IEntityType>The mapped entity types.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
mappedTypesIReadOnlyList<IEntityType>The mapped entity types.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
mappedTypesIReadOnlyList<IEntityType>The mapped entity types.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
mappedTypesIReadOnlyList<IEntityType>The mapped entity types.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
mappedTypesIReadOnlyList<IEntityType>The mapped entity types.
storeObjectStoreObjectIdentifierThe table identifier.
loggerIDiagnosticsLogger<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
mappedTypesIReadOnlyList<IEntityType>The mapped entity types.
storeObjectStoreObjectIdentifierThe identifier of the store object.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
mappedTypesIReadOnlyList<IEntityType>The mapped entity types.
viewNamestringThe view name.
schemastringThe schema.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
modelIModelThe model to validate.
loggerIDiagnosticsLogger<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
entityTypeIEntityTypeThe entity type.
keyIKeyThe key.
loggerIDiagnosticsLogger<Validation>The logger to use.