Table of Contents

Class RelationalModelValidator

Namespace
Microsoft.EntityFrameworkCore.Infrastructure
Assembly
Microsoft.EntityFrameworkCore.Relational.dll

The validator that enforces rules common for all relational providers.

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.

public class RelationalModelValidator : ModelValidator
Inheritance
RelationalModelValidator

Constructors

RelationalModelValidator(ModelValidatorDependencies, RelationalModelValidatorDependencies)

Creates a new instance of RelationalModelValidator.

public RelationalModelValidator(ModelValidatorDependencies dependencies, RelationalModelValidatorDependencies relationalDependencies)

Parameters

dependencies ModelValidatorDependencies

Parameter object containing dependencies for this service.

relationalDependencies RelationalModelValidatorDependencies

Parameter object containing relational dependencies for this service.

Properties

RelationalDependencies

Dependencies used to create a Microsoft.EntityFrameworkCore.Infrastructure.ModelValidator

protected virtual RelationalModelValidatorDependencies RelationalDependencies { get; }

Property Value

RelationalModelValidatorDependencies

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 IProperty

The property to get the default value for.

storeObject StoreObjectIdentifier

The identifier of the store object.

Returns

object

The object that is used as the default value for the column the property is mapped to.

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 IModel

The 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 IModel

The model to validate.

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 IForeignKey

A foreign key.

duplicateForeignKey IForeignKey

Another foreign key.

foreignKeyName string

The foreign key constraint name.

storeObject StoreObjectIdentifier

The 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 IIndex

An index.

duplicateIndex IIndex

Another index.

indexName string

The name of the index.

storeObject StoreObjectIdentifier

The 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 IKey

A key.

duplicateKey IKey

Another key.

keyName string

The name of the unique constraint.

storeObject StoreObjectIdentifier

The 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 IProperty

A property.

duplicateProperty IProperty

Another property.

columnName string

The column name.

storeObject StoreObjectIdentifier

The 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 IModel

The 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 IModel

The 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 IModel

The 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 IModel

The 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 IModel

The model to validate.

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 StoreObjectIdentifier

The 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 StoreObjectIdentifier

The 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 StoreObjectIdentifier

The 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 StoreObjectIdentifier

The 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 IModel

The model to validate.

logger IDiagnosticsLogger<Validation>

The logger to use.

ValidateSharedTableCompatibility(IReadOnlyList<IEntityType>, string, string, IDiagnosticsLogger<Validation>)

Validates the compatibility of entity types sharing a given table.

protected virtual void ValidateSharedTableCompatibility(IReadOnlyList<IEntityType> mappedTypes, string tableName, string schema, IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)

Parameters

mappedTypes IReadOnlyList<IEntityType>

The mapped entity types.

tableName string

The table name.

schema string

The schema.

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 IModel

The 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 string

The view name.

schema string

The 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 IModel

The model to validate.

logger IDiagnosticsLogger<Validation>

The logger to use.