Overview of ADO.NET


The ADO.NET programming model is built around two groups of objects:

  • Managed provider objects: These objects provide direct, connected access to a data source and the ability to directly interact with a data source. This group includes the Connection, Command, DataAdapter, and DataReader objects. The DataReader object provides streaming, forward-only, read-only access to a data source and is the fastest way to access a data source.

  • The DataSet object: This object provides disconnected access to a data source, that is, without a persistent connection to the parent data source. In fact, the DataSet object has no ability to directly connect to a data source. Instead, the DataAdapter object acts as the intermediary between the DataSet object and the data source. The DataSet object provides the ability to navigate through hierarchical data and to manipulate data and the underlying schema, all without a persistent connection to the parent data source. The DataSet object tracks all changes made to the data set so that they may be later merged with the parent data source. Finally, the DataSet object has the ability to serialize to Extensible Markup Language (XML) as an XML data document , which is simply an XML document that preserves relational information.

The .NET Framework provides a number of namespaces that relate both directly and indirectly to data access (see Table 3-1).

Table 3-1: .NET Framework Namespaces Involved in Data Access

NAMESPACE

DESCRIPTION

System.Data

Provides base classes for ADO.NET, focused on the DataSet class and its child classes, such as DataRow, DataColumn, and DataRelation.

System.Data.SqlClient

The SQL Server .NET data provider.

System.Data.OleDb

The OLE DB .NET data provider.

System.Data.Common

Provides classes that are shared by all .NET data providers. Many of these classes are abstract and may be used to create custom data providers.

System.Data.SqlTypes

Provides classes for native data types in SQL Server.

System.Xml

Provides classes for processing XML.

System.Xml.Schema

Provides classes for processing XML Schema Definition (XSD) schema files.

System.Xml.Xsl

Provides classes for processing Extensible Stylesheet Transformation (XSLT) transforms.

Figure 3-1 depicts the ADO.NET architecture and highlights the two distinct groups of objects in the model, namely, the .NET data provider, and the DataSet.

click to expand
Figure 3-1: ADO.NET architecture

The DataSet side of the architecture is contained within the System.Data namespace. The .NET data provider side of the architecture depends on the nature of the backend data source and is contained either within the System.Data.SqlClient namespace or within the System.Data.OleDb namespace. The DataSet is strongly integrated with XML, as depicted by a double-headed arrow in the figure. The DataSet has no direct link to the data source but instead communicates via the .NET data provider. Table 3-2 summarizes the ADO.NET objects covered in this chapter.

Table 3-2: Important ADO.NET Objects

OBJECT

DESCRIPTION

Connection

Provides connectivity to the data source.

Command

Enables access to database commands for returning data, modifying data, running stored procedures, and sending or retrieving parameter information. Includes explicit functionality such as the ExecuteScalar() method for queries that return one summarized value and the ExecuteNonQuery() method for commands that do not return a resultset.

DataReader

Provides highly optimized, non-cached, forward-only, read-only streaming data access.

XmlReader

Provides highly optimized, non-cached, forward-only, read-only access to an XML data stream. This object contains the resultset for SQL Server stored procedures that contain the FOR XML clause. This object cannot be used for stored procedures that return standard resultsets.

DataAdapter

Provides the bridge between the DataSet object and the data source. The DataAdapter object uses a set of Command objects for selecting, inserting, updating, and deleting data in the data source. The DataSet communicates directly with the DataAdapter object, which in turn communicates the request to the data source.

DataSet

An in-memory representation of one or more tables with records, constraints on columns , and relations among tables. You can use it for storing and manipulating disconnected relational data, flat data, or XML data.

Typed DataSet

A specialized class that inherits from the DataSet class and that provides access to data using strongly typed methods , properties, and events. You can access data tables and columns by name , rather than by using collection-based syntax. A typed DataSet is generated using XSD schema information. The .NET Framework SDK provides a command-line tool called XSD.exe for generating typed DataSets. Visual Studio.NET provides alternate access to this tool within the XML Designer."

DataView

Provides an optimized, customized view of a DataTable. One DataSet object can have several associated DataView objects, each of which contains a different, filtered view of the same data set. DataView objects are also disconnected from the parent data source.

Note

We often refer to a data provider object by its common name, such as DataReader instead of SqlDataReader. This implies that the discussion applies equally to all data providers. If we discuss a feature that is unique to a specific data provider, then we will refer to the specific version of the data provider object.




Performance Tuning and Optimizing ASP. NET Applications
Performance Tuning and Optimizing ASP.NET Applications
ISBN: 1590590724
EAN: 2147483647
Year: 2005
Pages: 91

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net