Hope this helps:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using System.Xml;
using NHibernate.SqlTypes;
using NHibernate.UserTypes;
using System.Data.SqlClient;
namespace NHibernate.Xml
{
/// <summary>
///
/// </summary>
[Serializable]
public class XmlType :
IUserType
{
/// <summary>
/// Determines whether the specified <see cref="System.Object"/
> is equal to this instance.
/// </summary>
/// <param name="x">The <see cref="System.Object"/> to compare
with this instance.</param>
/// <param name="y">The y.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="System.Object"/>
is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public new bool Equals(object x, object y)
{
if (x == null || y == null)
return false;
var xdoc_x = (XmlDocument)x;
var xdoc_y = (XmlDocument)y;
return xdoc_y.OuterXml == xdoc_x.OuterXml;
}
/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <param name="x">The x.</param>
/// <returns>
/// A hash code for this instance, suitable for use in hashing
algorithms and data structures like a hash table.
/// </returns>
public int GetHashCode(object x)
{
return x.GetHashCode();
}
public object NullSafeGet(IDataReader rs, string[] names,
object owner)
{
if (names.Length != 1)
throw new InvalidOperationException("names array has
more than one element. can't handle this!");
var document = new XmlDocument();
var val = rs[names[0]] as string;
if (val != null)
{
document.LoadXml(val);
return document;
}
return null;
}
public void NullSafeSet(IDbCommand cmd, object value, int
index)
{
var parameter = (DbParameter)cmd.Parameters[index];
if (value == null)
{
parameter.Value = DBNull.Value;
return;
}
parameter.Value = ((XmlDocument)value).OuterXml;
}
public object DeepCopy(object value)
{
var toCopy = value as XmlDocument;
if (toCopy == null)
return null;
var copy = new XmlDocument();
copy.LoadXml(toCopy.OuterXml);
return copy;
}
public object Replace(object original, object target, object
owner)
{
throw new NotImplementedException();
}
public object Assemble(object cached, object owner)
{
var str = cached as string;
if (str != null)
{
var doc = new XmlDocument();
doc.LoadXml(str);
return doc;
}
else
{
return null;
}
}
public object Disassemble(object value)
{
var val = value as XmlDocument;
if (val != null)
{
return val.OuterXml;
}
else
{
return null;
}
}
public SqlType[] SqlTypes
{
get
{
return new SqlType[] { new SqlXmlType() };
}
}
public System.Type ReturnedType
{
get { return typeof(XmlDocument); }
}
public bool IsMutable
{
get { return true; }
}
}
/// <summary>
///
/// </summary>
[Serializable]
public class SqlXmlType : SqlType
{
/// <summary>
/// Initializes a new instance of the <see cref="SqlXmlType"/>
class.
/// </summary>
public SqlXmlType()
: base(DbType.Xml)
{
}
}
}
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.