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)

System.Object
  System.Data.Entity.DbModelBuilder

public class DbModelBuilder

NameDescription
System_CAPS_pubmethodDbModelBuilder()

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.

System_CAPS_pubmethodDbModelBuilder(DbModelBuilderVersion)

Initializes a new instance of the DbModelBuilder class that will use a specific set of conventions to discover the initial model.

NameDescription
System_CAPS_pubpropertyConfigurations

Gets the ConfigurationRegistrar for this DbModelBuilder. The registrar allows derived entity and complex type configurations to be registered with this builder.

System_CAPS_pubpropertyConventions

Provides access to the settings of this DbModelBuilder that deal with conventions.

NameDescription
System_CAPS_pubmethodBuild(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.

System_CAPS_pubmethodBuild(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 (i.e. '2005', '2008' etc.)

System_CAPS_pubmethodComplexType<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.

System_CAPS_pubmethodEntity<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.

System_CAPS_pubmethodEquals(Object)

Specifies whether the DbModelBuilder is equal to the specified object.(Overrides Object.Equals(Object).)

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Returns the hash code for the current instance.(Overrides Object.GetHashCode().)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.

System_CAPS_pubmethodHasDefaultSchema(String)

Configures the default database schema name. This default database schema name is used for database objects that do not have an explicitly configured schema name.

System_CAPS_pubmethodIgnore(IEnumerable<Type>)

Excludes the specified type(s) from the model. This is used to remove types from the model that were added by convention during initial model discovery.

System_CAPS_pubmethodIgnore<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.

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodProperties()

Begins configuration of a lightweight convention that applies to all properties in the model.

System_CAPS_pubmethodProperties<T>()

Begins configuration of a lightweight convention that applies to all primitive properties of the specified type in the model.

System_CAPS_pubmethodRegisterEntityType(Type)

Registers an entity type as part of the model.

System_CAPS_pubmethodToString()

Returns a string representation of DbModelBuilder.(Overrides Object.ToString().)

System_CAPS_pubmethodTypes()

Begins configuration of a lightweight convention that applies to all entities and complex types in the model.

System_CAPS_pubmethodTypes<T>()

Begins configuration of a lightweight convention that applies to all entities and complex types in the model that inherit from or implement the type specified by the generic argument. This method does not register types as part of the model.

DbModelBuilder is typically used to configure a model by overriding OnModelCreating . You can also use DbModelBuilder independently of DbContext to build a model and then construct a DbContext or ObjectContext. The recommended approach, however, is to use OnModelCreating 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 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 via the DbModelBuilder API takes precedence over data annotations which in turn take precedence over the default conventions.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: