NHibernate-在孙对象上设置获取模式 [英] NHibernate - set fetch mode on grandchildren objects

查看:59
本文介绍了NHibernate-在孙对象上设置获取模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下条件查询(使用Lambda扩展名):

I have the following Criteria query (using Lambda extensions):

var workflowResult = repository.GetSession() 
                .CreateCriteria<Core.Domain.Application>() 
                .SetFetchMode<Core.Domain.Application>(app => app.ApplicationWorkflows, FetchMode.Join)  
                .SetResultTransformer(new DistinctRootEntityResultTransformer()) 
                .Future<Core.Domain.Application>(); 

这正常工作.每个应用程序都会急切地加载 ApplicationWorkflows集合.但是,我想更深入一点 并加载每个ApplicationWorkflow的ApplicationStatus对象.一世 可以使用以下HQL进行此操作,但希望将其翻译为 条件:

This is working correctly. Each Application eagerly loads the ApplicationWorkflows collection. However, I'd like to go one deeper and load the ApplicationStatus object of each ApplicationWorkflow. I can do this with the following HQL but would like to translate to Criteria:

var workflowQuery = "SELECT DISTINCT app" + 
                               " FROM Application app" + 
                               " JOIN FETCH app.ApplicationWorkflows awf" + 
                               " JOIN FETCH awf.ApplicationStatus"; 

已建议我使用以下内容,但在所有情况下都存在问题:

I've been advised to use the following, but am having issues with it working in all cases:

.SetFetchMode<Core.Domain.Application>(app => app.ApplicationWorkflows[0].ApplicationStatus, FetchMode.Join)

推荐答案

尝试一下.

var workflowResult = repository.GetSession() 
                .CreateCriteria<Core.Domain.Application>() 
                .CreateAlias("ApplicationWorkflows", "awf") 
                .SetFetchMode("ApplicationWorkflows", FetchMode.Join)  
                .SetFetchMode("awf.ApplicationStatus", FetchMode.Join)  
                .SetResultTransformer(new DistinctRootEntityResultTransformer()) 
                .Future<Core.Domain.Application>(); 

这篇关于NHibernate-在孙对象上设置获取模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆