I have a class that contains a property of type XmlElement. The property is mapped as following:
<property name="XamlForm" column="XamlForm" type="KTN.Base.Data.Types.XmlType, KTN.Base.Data" />
The XmlType class:
[Serializable]
public class XmlType : IUserType
{
public new bool Equals(object x, object y)
{
XmlElement xdoc_x = (XmlElement)x;
XmlElement xdoc_y = (XmlElement)y;
if (xdoc_x == null && xdoc_y == null) return true;
if (xdoc_x == null || xdoc_y == null) return false;
return xdoc_y.OuterXml == xdoc_x.OuterXml;
}
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!");
XmlDocument document = new XmlDocument();
string val = rs[names[0]] as string;
if (val != null)
{
document.LoadXml(val);
return document.DocumentElement;
}
return null;
}
public void NullSafeSet(IDbCommand cmd, object value, int index)
{
DbParameter parameter = (DbParameter)cmd.Parameters[index];
if (value == null)
{
parameter.Value = DBNull.Value;
return;
}
parameter.Value = ((XmlElement)value).OuterXml;
}
public object DeepCopy(object value)
{
if (value == null) return null;
XmlElement other = (XmlElement)value;
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(other.OuterXml);
return xdoc.DocumentElement; /**/
}
public SqlType[] SqlTypes
{
get
{
开发者_开发问答 return new SqlType[] { new SqlXmlType() };
}
}
public System.Type ReturnedType
{
get { return typeof(XmlDocument); }
}
public bool IsMutable
{
get { return true; }
}
public object Assemble(object cached, object owner)
{
return cached;
}
public object Disassemble(object value)
{
return value;
}
public int GetHashCode(object x)
{
return x.GetHashCode();
}
public object Replace(object original, object target, object owner)
{
// Changed return original to return target...
return target;
}
}
After invoke the function Merge from NHibernate, this property is null. Any Idea? Thanks in advance
NHibernate 3 has out of the box types for both XDocument
and XmlDocument
.
You shouldn't need to roll your own.
精彩评论