1
votes

I am new to NHibernate and am facing some issues with Fluent NHibernate automap.

I am using Nhibernate 3.3.3.400, Fluent Nhibernate 1.3.0.733 Automapper 2.2.1

I have a column in Database which is of type Xml. When I try to create a ma mapping column it give me the following error.

An association from the table Product refers to an unmapped class: System.Xml.XmlDocument

Following is the code I am trying to implement.

using System.Collections.Generic;
using System.Xml;

//using System.Xml.Linq;

namespace Examples.FirstAutomappedProject.Entities
{
    public class Product
    {
        public virtual int Id { get; protected set; }
        public virtual string Name { get; set; }
        public virtual double Price { get; set; }
        public virtual Location Location { get; set; }
        public virtual IList<Store> StoresStockedIn { get; set; }
        public virtual XmlDocument SalesRange { get; set; }

        public Product()
        {
            StoresStockedIn = new List<Store>();
        }
    }
}

I have been struggling for a couple of days now anhy help or samples would be greatly appreciated.

2

2 Answers

2
votes

it seems it FNH will not map it on it's own. you'll need a Override there

Map(x => x.SalesRange).CustomType<NHibernate.Type.XmlDocType>();
0
votes

Since Firo has sent his answer in comment I am answering it on his behalf.

basically here is what I ended up doing.

I created an override class as follows

using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Alterations;
using Examples.FirstAutomappedProject.Entities;
using NHibernate.Mapping;
using NHibernate.Type;

namespace Examples.FirstAutomappedProject.Overrides
{
    public class OrderQueueOverride : IAutoMappingOverride<Product>
    {
        public void Override(AutoMapping<Product> mapping)
        {
            mapping.Map(x => x.SalesRange).CustomType<XmlDocType>();
        }
    }
}

So the auto mapper will pick this override and map the column accodingly.