Show / Hide Table of Contents

Class SqlCommandXml

Serializer/deserializer for SqlCommand objects, to/from XML. This class is currently a prototype that will handle most SELECT queries; however, group by as well as mathematical and aggregate functions are not yet handled. Other query kinds, such as INSERT or UNION, are not yet handled at all, though it is fairly obivous how that should be implemented :-).

Inheritance
object
SqlCommandXml
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
Namespace: SuperOffice.Data.Dialect
Assembly: SoDataBase.dll
Syntax
public sealed class SqlCommandXml
Remarks

The class uses reflection on its members to map serialization methods to elements in the SqlCommand. Mappings are cached so the overhead is minimal. In the code, ToXml and Parse methods occur in complementary pairs, and mirror each other.

Examples

Serialization:

Select myCommand = S.NewSelect();
// add return fields, restrictions, etc
XmlDocument mySerialized = new SqlCommandXml().Serialize( myCommand );

Deserialization (from a file known to contain a Select, for illustration purposes):

XmlDocument mySerialized = new XmlDocument();
mySerialized.LoadXml( File.ReadAllText( path ) );
Select mySelect = new SqlCommandXml().DeSerialize( mySerialized ) as Select;
// now you can execute it if you want...
using( QueryExecutionHelper qeh = new QueryExecutionHelper( mySelect ) )
{
	while( qeh.Reader.Read() )
	{
		// process result row ...
	}
}

Constructors

SqlCommandXml()

Construct the instance, and set up the method call cache if needed (static)

Declaration
public SqlCommandXml()
Remarks

The class uses reflection on its members to map serialization methods to elements in the SqlCommand. Mappings are cached so the overhead is minimal. In the code, ToXml and Parse methods occur in complementary pairs, and mirror each other.

Methods

DeSerialize(XmlDocument)

Convert an XmlDocument representing a query into the equivalent SqlCommand (deserialization).

Declaration
public SqlCommand DeSerialize(XmlDocument xml)
Parameters
Type Name Description
XmlDocument xml

Xml to convert. NOTE: Currently this is limited to a SELECT, not using group by or aggregation or mathematical or conversion operators

Returns
Type Description
SqlCommand

SqlCommand of type Select

Remarks

The class uses reflection on its members to map serialization methods to elements in the SqlCommand. Mappings are cached so the overhead is minimal. In the code, ToXml and Parse methods occur in complementary pairs, and mirror each other.

Serialize(SqlCommand)

Convert an SqlCommand into an XmlDocument (serialization). All elements of the command including values are converted.

Declaration
public XmlDocument Serialize(SqlCommand command)
Parameters
Type Name Description
SqlCommand command

SqlCommand to convert. NOTE: Currently this is limited to a SELECT, not using group by or aggregation or mathematical or conversion operators.

Returns
Type Description
XmlDocument

populated Xml document object

Remarks

The class uses reflection on its members to map serialization methods to elements in the SqlCommand. Mappings are cached so the overhead is minimal. In the code, ToXml and Parse methods occur in complementary pairs, and mirror each other.

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
ObjectExtensions.AssignByReflection<T>(T, T)
ObjectExtensions.GraphCopy<T>(T)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top