The code archive for the Songhay Data Namespace is available at CodePlex.com in the Songhay System Data Access Framework.
This document summarizes the design goals and designer intentions behind the Songhay.Data namespace, written in C# for .NET 2.0.50727. This namespace provides all Songhay System applications access to DBMS data. It is the core of the Songhay System Data Access Framework. This small framework does not recognize the problem of mapping relational data to .NET objects in larger frameworks like NHibernate or LLBLGen. This framework is a rendition of a fraction of what’s in the DataContext in LINQ. It is best to place the purpose for this framework in the context of moving out of SQL 2000 DTS and going straight to managed code (veering away from the gigantic, official replacement for DTS, SQL Server Integration Services).
The characteristics of the Songhay.Data namespace are governed by these strong words:
The strong word Activity implies there are ‘activities’ associated with data. These activities operate under a contract by the interface IDataActivityAssembly, defining the Data Activity Assembly. The XML configuration of the Data Activity Assembly is de-serialized into the DataAccessConfiguration class—specifically, its array of DataAccessItem objects. The DataAccessItem allows the Data Activity Assembly to load components implementing the ICommandHandler interface when needed. It follows that these two interfaces, IDataActivityAssembly and ICommandHandler, define an actor and a receiver—a primal, input-output system for data access.
The strong word Common indicates support for the System.Data.Common namespace. This is a move toward supporting the widest range of data stores possible based on the assumption that Microsoft (and the Mono team) will continue to invest in the System.Data.Common namespace—and, in fact, Microsoft would use assets in this namespace to support LINQ and the Entity Framework “under the hood.”
As a courtesy—to warn early and often—it must said that the Songhay.Data namespace prioritizes XML-over-HTTP scenarios. This immediately means that the “data set” in this space will, by default, be the XPathDocument.
The XML configuration of the Data Activity Assembly is defined by the composite, DataAccessConfiguration partial classes. Since this is composed of partial classes, most of the members of this class are generated by the XML Schema Definition Tool (Xsd.exe).
DataAccessConfiguration()
|
The constructor of this class takes a parameter that specifies an XML file, valid for the schema in DataAccessConfiguration.xsd. |
DataAccessItem[]
|
An array of DataAccessItem (see below). |
GetDataAccessItem()
|
Uses an anonymous delegate to return a DataAccessItem based on the specified DataAccessItem.Name or the static overload is used to load a DataAccessItem from the specified XML file and XPath Query. |
The DataAccessItem composite of partial classes provides the information needed to access data. A DataAccessConfiguration object contains one or more of these items. Multiple items of type DataAccessItem available at the command line or on a Web server provide a flexible, simple way to associate many procedural activities with many data stores.
Connection[]
|
An array of Songhay.Data.Connection. Zero or more Songhay.Data.Connection objects are used to provide data store connection information. |
DisplayName
|
The human-readable name of the DataAccessItem. |
GetConnection()
|
Uses an anonymous delegate to return a Songhay.Data.Connection based on the specified Connection.Name. |
GetNameValuePair()
|
Uses an anonymous delegate to return a Songhay.Data.NameValue pair based on the specified NameValue.Name. |
Name
|
The unique name of the This value is used in one of the overloads for |
NameValuePair[]
|
An array of These provide the means to “hard code” a relatively generic data activity to a specific problem domain. |
Path
|
The path to the Data Activity Assembly used for data access. |
TypeName
|
The fully-qualified, type name of the Data Activity Assembly used for data access. This type must implement the IDataActivityAssembly interface (see below). |
Songhay.Data.Connection objects are used to provide data store connection information.
ConnectionString
|
A valid connection string. |
DisplayName
|
The human-readable name of the connection. |
Name
|
The unique name of the connection. This value is used for |
InvariantProviderName
|
The ADO.NET invariant provider name for a System.Data.DbConnection. For SQL Server, the name is "System.Data.SqlClient". |
NameValuePair objects can be used to provide parameters for DataAccessItem. These provide the means to “hard code” a relatively generic data activity to a specific problem domain.
Name
|
The unique name of the pair. This value is used for |
Value
|
The value of the pair. |
The IDataActivityAssembly interface defines the execution contract for Data Activity assemblies. The Data Activity Assembly cannot run in this framework without implementing this contract.
Execute()
|
This method is used to run or execute the Data Activity Assembly based on the specified DataAccessItem (see above). |
Log
|
This property contains all of the runtime messages generated and captured for this class. |
WriteLog
|
This event, with delegate The type |
The DataActivityAssembly class implements the IDataActivityAssembly interface. This is a “base” class for a Data Activity that provides event-logging support for the System.Data.Common.DbConnection.
Execute()
|
Implements member of IDataActivityAssembly interface (see above). |
Log
|
Implements member of IDataActivityAssembly interface (see above). |
WriteLog
|
Implements member of IDataActivityAssembly interface (see above). |
CnnStateChange()
|
Handles the DbConnection.StateChange() event, calling WriteToLog(). |
WriteToLog()
|
Takes message data from the Data Activity and fires the WriteLog event. |
The CommonDbms class provides generic procedures for data access.
Close()
|
Attempts to close the specified This method should be used rarely because |
DoCommand()
|
Executes the specified statement for the specified This member returns the integer value of the records affected by the statement. An optional |
GetAdapter()
|
Returns a When an optional connection string and a |
GetConnection()
|
Returns a System.Data.Common.DbConnection based on the specified invariant provider name and connection string. |
The CommonParameter class provides a few static helper members for System.Data.Common.DbParameter.
GetParameter()
|
Returns a DbParameter based on the specified DbCommand, parameter name and value (this is optional). You have the option of supplying |
GetParameters()
|
Returns an array of DbParameter based on the specified DbCommand and a Dictionary<String, Object> of parameters. |
The CommonReader class provides a few static helper members for System.Data.Common.DbDataReader.
GetReader()
|
Returns a DbDataReader based on the specified You have the option of supplying a You also have the option of supplying an ambient |
GetXPathDocument()
|
Returns an You have option of specifying a (local) row element name as well. Instead of a |
The CommonScalar class provides a few static helper members for System.Data.Common.DbDataReader. This defines the ‘Common Scalar’ as a string representation of relational data. This is deliberately designed to take advantage of SQL Sever 2005 queries like this:
DECLARE @xml XML
SET @xml = (SELECT * FROM MyTable FOR XML AUTO, ELEMENTS, ROOT('RootElement'))
SELECT @xml
This pattern emerges from the problem documented in “SQL Server 2005 PROBLEM: Using the ADO.NET DbCommand.ExecuteScalar() Method Truncates at 2033 Characters.”
GetString()
|
Returns a well-formed XML string based on the specified You have the option of supplying a This member is used in XML-over-HTTP designs serving AJAX clients. |
The ICommandHandler interface defines how a data access layer should accept external commands and respond to these commands. This interface was built to handle primitive XML-over-HTTP communication as lightweight alternative to formal SOAP-based implementations.
The use of this interface and an ASP.NET *.ASHX page, for example, is a very agile way to get an AJAX server up and running for vendor-agnostic HTTP clients.
DoCommand()
|
Returns an One |