1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using NHibernate . Engine ;
3
4
using NHibernate . Loader ;
4
5
using NHibernate . Loader . Criteria ;
6
+ using NHibernate . Persister . Entity ;
5
7
using NHibernate . SqlCommand ;
6
8
using NHibernate . Type ;
7
9
using IQueryable = NHibernate . Persister . Entity . IQueryable ;
@@ -38,10 +40,16 @@ public EntityProjection(System.Type entityType, string entityAlias)
38
40
}
39
41
40
42
/// <summary>
41
- /// Fetch lazy properties
43
+ /// Fetch all lazy properties
42
44
/// </summary>
43
45
public bool FetchLazyProperties { get ; set ; }
44
46
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
+
45
53
/// <summary>
46
54
/// Lazy load entity
47
55
/// </summary>
@@ -63,14 +71,25 @@ public EntityProjection SetLazy(bool lazy = true)
63
71
}
64
72
65
73
/// <summary>
66
- /// Fetch lazy properties
74
+ /// Fetch all lazy properties
67
75
/// </summary>
68
76
public EntityProjection SetFetchLazyProperties ( bool fetchLazyProperties = true )
69
77
{
70
78
FetchLazyProperties = fetchLazyProperties ;
71
79
return this ;
72
80
}
73
81
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
+
74
93
#endregion Configuration methods
75
94
76
95
#region IProjection implementation
@@ -115,7 +134,14 @@ SqlString IProjection.ToSqlString(ICriteria criteria, int position, ICriteriaQue
115
134
? identifierSelectFragment
116
135
: string . Concat (
117
136
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 ) ;
119
145
}
120
146
121
147
SqlString IProjection . ToGroupSqlString ( ICriteria criteria , ICriteriaQuery criteriaQuery )
0 commit comments