NHibernate - set the sampling mode to grandchild objects

I have the following Criteria request (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>(); 

This is working correctly. Each application eagerly downloads the ApplicationWorkflows Collection. However, I would like to go deeper and load the ApplicationStatus object of each ApplicationWorkflow. I can do this with the following HQL, but would like to translate into Criteria:

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

I was advised to use the following, but my problems with it work in all cases:

.SetFetchMode<Core.Domain.Application>(app => app.ApplicationWorkflows[0].ApplicationStatus, FetchMode.Join)
+3
source share
1 answer

Try it.

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>(); 
0
source

Source: https://habr.com/ru/post/1753605/


All Articles