DbModelBuilder Class
DbModelBuilder is used to map CLR classes to a database schema. This code centric approach to building an Entity Data Model (EDM) model is known as Code First.
Namespace: System.Data.Entity
Assembly: EntityFramework (in EntityFramework.dll)
The DbModelBuilder type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | DbModelBuilder | Initializes a new instance of the DbModelBuilder class. The process of discovering the initial model will use the set of conventions included in the most recent version of the Entity Framework installed on your machine. |
![]() | DbModelBuilder(DbModelBuilderVersion) | Initializes a new instance of the DbModelBuilder class that will use a specific set of conventions to discover the initial model. |
| Name | Description | |
|---|---|---|
![]() | Configurations | Gets the ConfigurationRegistrar for this DbModelBuilder. The registrar allows derived entity and complex type configurations to be registered with this builder. |
![]() | Conventions | Provides access to the settings of this DbModelBuilder that deal with conventions. |
| Name | Description | |
|---|---|---|
![]() | Build(DbConnection) | Creates a DbModel based on the configuration performed using this builder. The connection is used to determine the database provider being used as this affects the database layer of the generated model. |
![]() | Build(DbProviderInfo) | Creates a DbModel based on the configuration performed using this builder. Provider information must be specified because this affects the database layer of the generated model. For SqlClient the invariant name is 'System.Data.SqlClient' and the manifest token is the version year (for example, '2005' or '2008'.) |
![]() | ComplexType(Of TComplexType) | Registers a type as a complex type in the model and returns an object that can be used to configure the complex type. This method can be called multiple times for the same type to perform multiple lines of configuration. |
![]() | Entity(Of TEntityType) | Registers an entity type as part of the model and returns an object that can be used to configure the entity. This method can be called multiple times for the same entity to perform multiple lines of configuration. |
![]() | Equals | Returns whether the specified model builder is equal to the current model builder. (Overrides Object.Equals(Object).) |
![]() | Finalize | (Inherited from Object.) |
![]() | GetHashCode | Returns the hash function for the specified model builder. (Overrides Object.GetHashCode.) |
![]() | GetType | Gets the type for the current model builder. |
![]() | Ignore(IEnumerable(Of Type)) | Excludes a type or types from the model. This is used to remove types from the model that were added by convention during initial model discovery. |
![]() | Ignore(Of T) | Excludes a type from the model. This is used to remove types from the model that were added by convention during initial model discovery. |
![]() | MemberwiseClone | (Inherited from Object.) |
![]() | ToString | Returns a string representation of the model builder. (Overrides Object.ToString.) |
DbModelBuilderis typically used to configure a model by overriding OnModelCreating(DbModelBuilder). You can also use the model builder independent of DbContextto build a model and then construct a DbContext or ObjectContext. The recommended approach, however, is to use OnModelCreating(DbModelBuilder) in DbContext as the workflow is more intuitive and takes care of common tasks, such as caching the created model. Types that form your model are registered with DbModelBuilder and optional configuration can be performed by applying data annotations to your classes and/or by using the fluent style DbModelBuilder API. When the Build method is called a set of conventions are run to discover the initial model. These conventions will automatically discover aspects of the model, such as primary keys, and will also process any data annotations that were specified on your classes. Finally any configuration that was performed using the DbModelBuilder API is applied. Configuration done by using the DbModelBuilder API takes precedence over data annotations which in turn take precedence over the default conventions.
