Monday, May 17, 2010

Data Access Application Block 5.0 – Part 1

The Enterprise Library Data Access Application Block simplifies the development of tasks that implement common data access functionality. Applications can use this application block in a variety of situations, such as reading data for display, passing data through application layers, and submitting changed data back to the database system.
The application block includes support for both stored procedures and inline SQL statements. Common housekeeping tasks, such as managing connections and creating and caching parameters, are encapsulated in the application block's methods. In other words, the Data Access Application Block provides access to the most often used features of ADO.NET in simple-to-use classes and provides a corresponding boost in developer productivity.
Enterprise Library 5.0 DAL allows users to retrieve data in a format that better match the real-world objects that the data represents. Prior to 5.0 I use to create my DataMapper implementation for mapping the domain entities with the IDbReader column values. Enterprise Library 5.0 DAL introduces the concept of Accessors, which accept information that is required to extract data and mappings that indicate how the input parameters correspond to the parameters of the underlying query. They use output mappings that define how the returned columns map to the properties of the objects the developer wants to work with, and return a sequence of objects of the specified type. The following schematic shows the high level process when using an accessor to retrieve data as an enumerable sequence of objects.

The DataAccessor class provides the Execute method that accepts and array of parameters for executing the command and uses the IRowMapper/ IResultSetMapper reference to create the required object from the resultset returned by the SPROC/ Query execution.