11using System ;
2+ using System . Collections . Generic ;
23using NHibernate . Engine ;
34using NHibernate . Loader ;
45using NHibernate . Loader . Criteria ;
6+ using NHibernate . Persister . Entity ;
57using NHibernate . SqlCommand ;
68using NHibernate . Type ;
79using IQueryable = NHibernate . Persister . Entity . IQueryable ;
@@ -38,10 +40,16 @@ public EntityProjection(System.Type entityType, string entityAlias)
3840 }
3941
4042 /// <summary>
41- /// Fetch lazy properties
43+ /// Fetch all lazy properties
4244 /// </summary>
4345 public bool FetchLazyProperties { get ; set ; }
4446
47+ /// <summary>
48+ /// Fetch individual lazy properties or property groups
49+ /// Note: To fetch single property it must be mapped with unique fetch group (lazy-group)
50+ /// </summary>
51+ public ICollection < string > FetchLazyPropertyGroups { get ; set ; }
52+
4553 /// <summary>
4654 /// Lazy load entity
4755 /// </summary>
@@ -63,14 +71,25 @@ public EntityProjection SetLazy(bool lazy = true)
6371 }
6472
6573 /// <summary>
66- /// Fetch lazy properties
74+ /// Fetch all lazy properties
6775 /// </summary>
6876 public EntityProjection SetFetchLazyProperties ( bool fetchLazyProperties = true )
6977 {
7078 FetchLazyProperties = fetchLazyProperties ;
7179 return this ;
7280 }
7381
82+ /// <summary>
83+ /// Fetch individual lazy properties or property groups
84+ /// Provide lazy property name and it will be fetched along with properties that belong to the same fetch group (lazy-group)
85+ /// Note: To fetch single property it must be mapped with unique fetch group (lazy-group)
86+ /// </summary>
87+ public EntityProjection SetFetchLazyPropertyGroups ( params string [ ] lazyPropertyGroups )
88+ {
89+ FetchLazyPropertyGroups = lazyPropertyGroups ;
90+ return this ;
91+ }
92+
7493 #endregion Configuration methods
7594
7695 #region IProjection implementation
@@ -115,7 +134,14 @@ SqlString IProjection.ToSqlString(ICriteria criteria, int position, ICriteriaQue
115134 ? identifierSelectFragment
116135 : string . Concat (
117136 identifierSelectFragment ,
118- Persister . PropertySelectFragment ( TableAlias , ColumnAliasSuffix , FetchLazyProperties ) ) ) ;
137+ GetPropertySelectFragment ( ) ) ) ;
138+ }
139+
140+ private string GetPropertySelectFragment ( )
141+ {
142+ return FetchLazyProperties
143+ ? Persister . PropertySelectFragment ( TableAlias , ColumnAliasSuffix , FetchLazyProperties )
144+ : Persister . PropertySelectFragment ( TableAlias , ColumnAliasSuffix , FetchLazyPropertyGroups ) ;
119145 }
120146
121147 SqlString IProjection . ToGroupSqlString ( ICriteria criteria , ICriteriaQuery criteriaQuery )
0 commit comments