Database Class
Entity Framework 5.0
An instances of this class is obtained from an DbContext object and can be used to manage the actual database backing a DbContext or connection. This includes creating, deleting, and checking for the existence of a database. Deletion and checking for existence of a database can be performed using just a connection (without a full context) by using the static methods of this class.
Namespace: System.Data.Entity
Assembly: EntityFramework (in EntityFramework.dll)
The Database type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Connection | Returns the connection being used by this context. This may cause the context to be initialized and the connection to be created if it does not already exist. |
![]() ![]() | DefaultConnectionFactory | The connection factory to use when creating a DbConnection from just a database name or a connection string. |
| Name | Description | |
|---|---|---|
![]() | CompatibleWithModel | This method returns true if the context has a model hash and the database contains a model hash and these hashes match. This indicates that the model used to create the database is the same as the current model and so the two can be used together. |
![]() | Create | Creates a new database on the database server for the model defined in the backing context. Note that calling this method before the database initialization strategy has run will disable executing that strategy. |
![]() | CreateIfNotExists | Creates a new database on the database server for the model defined in the backing context, but only if a database with the same name does not already exist on the server. |
![]() | Delete | Deletes the database on the database server if it exists, otherwise does nothing. |
![]() ![]() | Delete(DbConnection) | Deletes the database on the database server if it exists, otherwise does nothing. |
![]() ![]() | Delete(String) | Deletes the database on the database server if it exists, otherwise does nothing. The connection to the database is created using the given database name or connection string in the same way as is described in the documentation for the DbContext class. |
![]() | Equals | Returns whether the specified database is equal to the current database. (Overrides Object.Equals(Object).) |
![]() | ExecuteSqlCommand | Executes the given DDL/DML command against the database. |
![]() | Exists | Checks whether or not the database exists on the server. |
![]() ![]() | Exists(DbConnection) | Checks whether or not the database exists on the server. |
![]() ![]() | Exists(String) | Checks whether or not the database exists on the server. The connection to the database is created using the given database name or connection string in the same way as is described in the documentation for the DbContext class. |
![]() | Finalize | (Inherited from Object.) |
![]() | GetHashCode | Returns the hash function for the specified database. (Overrides Object.GetHashCode.) |
![]() | GetType | Gets the type for the current database. |
![]() | Initialize | Runs the registered IDatabaseInitializer(Of TContext) on this context. If the parameter force is set to true, then the initializer is run regardless of whether or not it has been run before. This can be useful if a database is deleted while an app is running and needs to be reinitialized. |
![]() | MemberwiseClone | (Inherited from Object.) |
![]() ![]() | SetInitializer(Of TContext) | Gets or sets the database initialization strategy. The database initialization strategy is called when DbContext instance is initialized from a DbCompiledModel. |
![]() | SqlQuery(Type, String, Object()) | Creates a raw SQL query that will return elements of the given type. The type can be any type that has properties that match the names of the columns returned from the query, or can be a simple primitive type. |
![]() | SqlQuery(Of TElement)(String, Object()) | Creates a raw SQL query that will return elements of the given generic type. The type can be any type that has properties that match the names of the columns returned from the query, or can be a simple primitive type. |
![]() | ToString | Returns a string representation of the database. (Overrides Object.ToString.) |
Show:
