Sitecore 5.0 API

Database Class

Represents a database.

For a list of all members of this type, see Database Members.

System.Object
   Sitecore.Data.Database

[Visual Basic]
Public Class Database
    Implements IInitializable
[C#]
public class Database : IInitializable

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

A database is a collection of items. A database uses a data source object to retrieve and store items. The data source is an concrete implementation that manages items in a storage, e.g. a SQL database or the file system.

Normally a database is obtained by using the Database property which specifies the current database. In the Sitecore client the current database refers to the Core database, while ContentDatabase refers to the Master database. To obtain a reference to another database, use the GetDatabase method.

A database can be read-only. An example of this is the FileSystem database which reflects the file directory structure of the website.

Database has intrinsic knowledge of the some of information stored in them. For instance the templates defined in the database can be accessed through the Templates property. Other examples include Aliases, Archives, Languages and Masters.

A database also implicitly contain resources such as layouts and media items. While the database may not actually contain the ASPX file of a layout it may contain a reference to it. Such resources can be accessed through the Resources property.

It is possible to add meta data to a database using the Properties collection. Properties consists of key/value pairs and are stored seperately. For instance the database version is stored in the meta data.

A database can have a number of indexes associated. Indexes are access through the Indexes property. Indexes allows items to be retrieved quickly.

A database can have a workflow associated.

Example

This example gets an item in a database.

public Item GetItem(string databaseName, string id, string language, string version) {
  ID itemID = ID.Parse(id);

  Language itemLanguage = Language.Parse(language);
  
  Sitecore.Data.Version itemVersion = Sitecore.Data.Version.Parse(version);

  Database database = Factory.GetDatabase(databaseName);

  if (database != null) {
    return database.Items[itemID, itemLanguage, itemVersion];
  }

  return null;
}

Requirements

Namespace: Sitecore.Data

Assembly: Sitecore.Kernel (in Sitecore.Kernel.dll)

See Also

Database Members | Sitecore.Data Namespace