I have made a start.

Mapping:

<class name="X" ...

    <property name="XML" column="XML">
      <type name="a.b.XmlType, a"></type>
    </property>

</class>

Code of XmlType below (cobbled together from the Internet). Problem:

var cfg = new Configuration();
cfg..Configure();
cfg.AddAssembly("Diseases");
new SchemaUpdate(cfg).Execute(false, true);

This works for all other classes (tables appear in db) but not for
this class (X). There is no exception as well.

Looking forward to any feedback. Thanks.

XmlType code:

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;

namespace a.b
{
    public class XmlType : IUserType
    {
        public new bool Equals(object x, object y)
        {
            XmlDocument xdoc_x = (XmlDocument) x;
            XmlDocument xdoc_y = (XmlDocument) y;
            return xdoc_y.OuterXml == xdoc_x.OuterXml;
        }

        public object Disassemble(object value)
        {
            throw new Exception("The method or operation is not
implemented.");
        }

        public int GetHashCode(object x)
        {
            throw new Exception("The method or operation is not
implemented.");
        }

        public object Replace(object original, object target, object
owner)
        {
            return original;
        }

        public object Assemble(object cached, object owner)
        {
            throw new Exception("The method or operation is not
implemented.");
        }

        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;
            }
            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 = ((XmlDocument) value).OuterXml;
        }

        public object DeepCopy(object value)
        {
            XmlDocument other = (XmlDocument) value;
            XmlDocument xdoc = new XmlDocument();
            xdoc.LoadXml(other.OuterXml);
            return xdoc;
        }

        public SqlType[] SqlTypes
        {
            get
            {
                return new SqlType[] { new SqlXmlType() };
            }
        }

        public System.Type ReturnedType
        {
            get { return typeof(XmlDocument); }
        }

        public bool IsMutable
        {
            get { return true; }
        }
    }

    public class SqlXmlType : SqlType
    {
        public SqlXmlType() : base(System.Data.DbType.Xml)
        {
        }
    }
}


On Sep 3, 9:14 am, csetzkorn <[email protected]> wrote:
> Hi,
>
> I have a class with a XmlDocument attribute (or XElement I do not
> care) which I would like to map to a column of the XML data type in
> SQL server 2005. I have done some googeling but did not get anywhere
> with the suggested solutions. Is anyone aware of a working/easy
> solution to my problem? Thanks a lot in advance.
>
> Best wishes,
>
> Christian
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to