I am exploring FluentNHibernate with NHibernate 3.0 and have run into
an issue that I'm hoping can be resolved easily either by a change in
how I'm doing something or an updated build somewhere.

Using the following fluent configuration:

SessionFactory = Fluently.Configure()
        .Cache(c => c
                .UseQueryCache()
                .UseSecondLevelCache()
                
.ProviderClass("NHibernate.Caches.SysCache.SysCacheProvider,NHibernate.Caches.SysCache")
                )
        .Database(MsSqlConfiguration.MsSql2008.ConnectionString(@"Server=.
\SQL2008;Database=fluentnhibernate_kyleheon;User
ID=applications;Password=applications;Trusted_Connection=False;"))
        .ExposeConfiguration(c =>
c.SetProperty("current_session_context_class", "web"))
        .Mappings(m =>
        
m.FluentMappings.AddFromAssembly(System.Reflection.Assembly.GetExecutingAssembly())
                )
        
.ProxyFactoryFactory(typeof(NHibernate.ByteCode.LinFu.ProxyFactoryFactory))
        .BuildSessionFactory();

and this code:

using (ISession session =
KyleHeon.Web.GlobalApplication.SessionFactory.OpenSession())
{
        using (session.BeginTransaction())
        {
                IQuery query = session.CreateQuery(@"
                        SELECT n
                        FROM Node AS n
                        JOIN FETCH n.Children
                        ORDER BY n.SortOrder"
                        )
                        .SetResultTransformer(new 
DistinctRootEntityResultTransformer());

                var nodes = query.List<KyleHeon.Web.Entities.Node>();

                this.rptNodes.DataSource = nodes.Where(n => n.Parent == null);
                this.rptNodes.DataBind();
        }
}

Everything works, I get my data back with children eagerly loaded and
I'm able to build a tree. For performance reasons I want to be able to
set this as cacheable, but when I do (using the following code) I get
an error:

IQuery query = session.CreateQuery(@"
        SELECT n
        FROM Node AS n
        JOIN FETCH n.Children
        ORDER BY n.SortOrder"
        )
        .SetResultTransformer(new DistinctRootEntityResultTransformer())
        .SetCacheable(true);

The error I get is below:

System.Reflection.TargetException: Object does not match target type.

var nodes = query.List<KyleHeon.Web.Entities.Node>();

Is there a different or better way to achieve the same thing while
keeping performance optimal (eagerly loading children)?

Thank you!

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to