Export (0) Print
Expand All

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.

System::Object
  System.Data.Entity::Database

Namespace:  System.Data.Entity
Assembly:  EntityFramework (in EntityFramework.dll)

public ref class Database

The Database type exposes the following members.

  NameDescription
Public propertyConnectionReturns 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.
Public propertyStatic memberDefaultConnectionFactoryThe connection factory to use when creating a DbConnection from just a database name or a connection string.
Top

  NameDescription
Public methodCompatibleWithModelThis 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.
Public methodCreateCreates 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.
Public methodCreateIfNotExistsCreates 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.
Public methodDelete()Deletes the database on the database server if it exists, otherwise does nothing.
Public methodStatic memberDelete(DbConnection)Deletes the database on the database server if it exists, otherwise does nothing.
Public methodStatic memberDelete(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.
Public methodEqualsReturns whether the specified database is equal to the current database. (Overrides Object::Equals(Object).)
Public methodExecuteSqlCommandExecutes the given DDL/DML command against the database.
Public methodExists()Checks whether or not the database exists on the server.
Public methodStatic memberExists(DbConnection)Checks whether or not the database exists on the server.
Public methodStatic memberExists(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.
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCodeReturns the hash function for the specified database. (Overrides Object::GetHashCode().)
Public methodGetTypeGets the type for the current database.
Public methodInitializeRuns the registered IDatabaseInitializer<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.
Protected methodMemberwiseClone (Inherited from Object.)
Public methodStatic memberSetInitializer<TContext>Gets or sets the database initialization strategy. The database initialization strategy is called when DbContext instance is initialized from a DbCompiledModel.
Public methodSqlQuery(Type, String, array<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.
Public methodSqlQuery<TElement>(String, array<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.
Public methodToStringReturns a string representation of the database. (Overrides Object::ToString().)
Top

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