Table of Contents

Class ModelSource

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

An implementation of IModelSource that produces a model based on the DbSet<TEntity> properties exposed on the context. The model is cached to avoid recreating it every time it is requested.

This type is typically used by database providers (and other extensions). It is generally not used in application code.

public class ModelSource : IModelSource
Inheritance
ModelSource
Implements
Inherited Members

Remarks

The service lifetime is Singleton. This means a single instance is used by many 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

ModelSource(ModelSourceDependencies)

Creates a new ModelSource instance.

public ModelSource(ModelSourceDependencies dependencies)

Parameters

dependencies ModelSourceDependencies

The dependencies to use.

Properties

Dependencies

Dependencies for this service.

protected virtual ModelSourceDependencies Dependencies { get; }

Property Value

ModelSourceDependencies

Methods

CreateModel(DbContext, IConventionSetBuilder, ModelDependencies)

Creates the model. This method is called when the model was not found in the cache.

protected virtual IModel CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, ModelDependencies modelDependencies)

Parameters

context DbContext

The context the model is being produced for.

conventionSetBuilder IConventionSetBuilder

The convention set to use when creating the model.

modelDependencies ModelDependencies

The dependencies object for the model.

Returns

IModel

The model to be used.

GetModel(DbContext, ModelCreationDependencies, bool)

Gets the model to be used.

public virtual IModel GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, bool designTime)

Parameters

context DbContext

The context the model is being produced for.

modelCreationDependencies ModelCreationDependencies

The dependencies object used during the creation of the model.

designTime bool

Whether the model should contain design-time configuration.

Returns

IModel

The model to be used.