I'm having difficulty using AutoMapper to convert Object from Nhibernate queries into my DTO in the following conf
Let's say I have 4 class.
class A
{
//some fields of built-in type
}
abstract class B //Some class derived this one, but this is not important here
{
//some fields of built-in type
public A refA { get; set; }
}
class C
{
//some fields of built-in type
public B refB { get; set; }
}
class D
{
//some fields of built-in type
public B refC { get; set; }
}
I use AutoMapper to convert it to my DTO, lets assume for simplicity here that the DTO is an exact copy of these class. I want to send this through the wire, so before serializing, I ask AutoMapper to convert it in the DTO corresponding to the D-Class.
If I make these Object and configure the field my-self, when I call
Mapper.Map<T1,T2>(T1 source)
This is working. So my configuration AutoMap is working. More its also working with
Mapper.Map<IList<T1>,List<T2>
Very well.
Now I make these object, I put them in a Database and call a request to my SQL DB with Nhibernate to retrieve an IList (List of class D).
If I now try to convert it in DTO, it doesnt work anymore.
I trace the code in AutoMap, it maps correctly all the built-in type field in class D
and then it comes to the refC
and here it crash somewhere.
I know about lazy-loading and the fact that Nhibernate just gimme a proxy of my ref to class C but I dont see how to solve this.
Just so you know the NHibernateUtil.IsInitialized(refC) is true
Many Thanks