I finally found the solution I think. I changed commented line to .ForMember(x => x.Info, y => y.ResolveUsing<NHibernateResolver>().FromMember(z => NHibernateUtil.IsPropertyInitialized(z, "Info") ? z.Info : null))
On 4 Paź, 20:42, lszk <[email protected]> wrote: > I'm using AutoMapper to map my entity to DTO. > > Mapper.CreateMap<ArticleInfo, ArticleInfoDTO>(); > Mapper.CreateMap<Article, ArticleDTO>() > .ForMember(x => x.Author, y => > y.ResolveUsing<NHibernateResolver>().FromMember(z => z.Author)) > //.ForMember(x => x.Info, y => > y.ResolveUsing<NHibernateResolver>().FromMember(z => z.Info)) > .ForMember(x => x.Info, y => y.Ignore()); > //... > > I'm doing it when the session is disconnected. To avoid problems with > lazyload, I have own value resolver: > > public class NHibernateResolver : ValueResolver<object, object> > { > protected override object ResolveCore(object source) > { > if (NHibernateUtil.IsInitialized(source)) > { > return source; > } > > return null; > } > } > > Everything works, expect situation when in my Article entity I have a > component (which has LazyLoad definied to). > If I uncomment this line for Info field (this is ArticleInfo object)), > then I have an exception: > > AutoMapper.AutoMapperMappingException: Trying to map > System.Collections.Generic.IList`1[[CMS.Domain.Entities.Article, > CMS.Infrastructure, Version=1.0.0.0, Culture=neutral, > PublicKeyToken=null]] to > System.Collections.Generic.List`1[[CMS.Services.DTOs.ArticleDTO, > CMS.Services, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]. > > Zg³oszono wyj±tek typu 'AutoMapper.AutoMapperMappingException'. ---> > AutoMapper.AutoMapperMappingException: Trying to map > CMS.Domain.Entities.Article to CMS.Services.DTOs.ArticleDTO. > > Using mapping configuration for CMS.Domain.Entities.Article to > CMS.Services.DTOs.ArticleDTO > Zg³oszono wyj±tek typu 'AutoMapper.AutoMapperMappingException'. ---> > AutoMapper.AutoMapperMappingException: Trying to map > Castle.Proxies.ArticleProxy to CMS.Services.DTOs.ArticleInfoDTO. > > Using mapping configuration for CMS.Domain.Entities.Article to > CMS.Services.DTOs.ArticleDTO > Destination property: Info > > Zg³oszono wyj±tek typu 'AutoMapper.AutoMapperMappingException'. ---> > NHibernate.LazyInitializationException: > Initializing[CMS.Domain.Entities.Article#]-session is not connected. > entity-name:'CMS.Domain.Entities.Article' property:'Info' -- 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.
