跳转到内容

ADO.NET

维基百科,自由的百科全书

这是本页的一个历史版本,由Rocman留言 | 贡献2006年4月22日 (六) 12:18编辑。这可能和当前版本存在着巨大的差异。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)

ADO.NET (or the new ActiveX Data Objects technology) is the primary relational data access model for Microsoft .NET-based applications. It may be used to access data sources for which there is a specific .NET Provider, or, via a .NET Bridge Provider, for which there is a specific OLE DB Provider, ODBC Driver, or JDBC Driver. ADO.NET is sometimes considered an evolution of ADO technology, but it is important to note that some major changes were made between the two.

Architecture

ADO.NET consists of two primary parts:

Data provider

The provider objects. These classes provide access to and communicate with a data source, such as a SQL Server database. Each data source has its own set of provider objects, but they each have a common set of suffixes:

  • Connection: Provides a connection to the data source, needed to access it. Also acts as an abstract factory for command objects.
  • Command: Used to perform some action on the data source, such as reading, updating, or deleting relational data.
  • Parameter: Describes a single parameter to a command. A common example is a parameter to a stored procedure.
  • DataAdapter: A bridge used to transfer data between a data source and a DataSet object (see below).
  • DataReader: An object used to efficiently process a large list of results one record at a time without storing them.

DataSet

The DataSet objects, a group of classes describing a simple in-memory relational database. There is only one, data-source-neutral, set of DataSet objects, but both data and database schema structure can be imported from other data sources with -DataAdapter objects. The classes form a containment hierarchy:

  • A DataSet object represents an entire database. It can contain tables and relationships between those tables.
    • A DataTable object represents a single table in the database. It has a name, rows, and columns.
      • A DataColumn represents a column of the table, including its name and type.
      • A DataRow object represents a single row in the table, and allows reading and updating of the values in that row, as well as retrieving any rows that are related to it through a primary-key foreign-key relationship.
    • A DataRelation is a relationship between tables, such as a primary-key foreign-key relationship. This is useful for enabling DataRow's functionality of retrieving related rows.
    • A Constraint describes an enforced property of the database, such as the uniqueness of the values in a primary key column. As data is modified any violations that arise will cause exceptions.

Sources of ADO.NET Providers

  • Microsoft ships providers for a few databases and a Bridge to ODBC drivers for use with the Microsoft CLR, on Windows
  • DataDirect Technologies ships 100% managed providers that are for the primary corporate databases (Oracle, Sybase, DB2, SQL Server, Progress RDBMS)
  • OpenLink Software ships providers for a number of target databases, including Bridges to other data access mechanisms, for use with either the Microsoft or Mono CLR implementations, on Windows,

ADO.NET and Visual Studio.NET

Functionality exists in the Visual Studio .NET IDE to create specialized subclasses of the DataSet classes for a particular database schema, allowing convenient access to each field through strongly-typed properties. This helps catch more programming errors at compile-time and makes the IDE's Intellisense feature more useful.

ADO Vs. ADO.NET

A useful discussion of the shift from ADO to ADO.NET may be found in the MSDN article ADO.NET for the ADO Programmer.

ObjectSpaces

ObjectSpaces is a set of data access APIs for the Microsoft .NET Framework, to be included with a future version of ADO.NET. ObjectSpaces allow data to be treated as objects, independent of the underlying datastore. In ObjectSpaces, data is exposed as object, which encapsulate their physical structure of tables, rows, columns etc.

ObjectSpaces data objects are known as persistent objects. These ObjectSpaces objects can be used to retrieve data from the datastore, navigate data using its relationships, modify the data, and commit the changes back on the datastore. ObjectSpaces includes different classes to connect to a relational datastore, such as a database, or to an XML Datastore. Both provides uniform methods to access data and encapsulates the communication with the datastore. In addition, these classes can be extended to create adapters for other types of datastores as well.

See also

References