@@ -43,8 +43,12 @@ public TranslatedQuery Translate()
4343 internal TranslatedQuery Translate ( ProjectionExpression projection ,
4444 IEnumerable < Parameter < Tuple > > tupleParameterBindings )
4545 {
46- var newItemProjector = projection . ItemProjector . EnsureEntityIsJoined ( ) ;
47- var result = projection . Apply ( newItemProjector ) ;
46+ var result = projection ;
47+ if ( context . SessionTags != null )
48+ result = ApplySessionTags ( result , context . SessionTags ) ;
49+ var newItemProjector = result . ItemProjector . EnsureEntityIsJoined ( ) ;
50+ result = result . Apply ( newItemProjector ) ;
51+
4852 var optimized = Optimize ( result ) ;
4953
5054 // Prepare cached query, if required
@@ -60,7 +64,7 @@ internal TranslatedQuery Translate(ProjectionExpression projection,
6064 var materializer = BuildMaterializer ( prepared , tupleParameterBindings ) ;
6165 var translatedQuery = new TranslatedQuery (
6266 compiled , materializer , prepared . ResultAccessMethod ,
63- projection . TupleParameterBindings , tupleParameterBindings ) ;
67+ result . TupleParameterBindings , tupleParameterBindings ) ;
6468
6569 // Providing the result to caching layer, if required
6670 if ( compiledQueryScope != null && ! translatedQuery . TupleParameters . Any ( ) ) {
@@ -104,6 +108,18 @@ private static ProjectionExpression PrepareCachedQuery(
104108 return origin ;
105109 }
106110
111+ private static ProjectionExpression ApplySessionTags ( ProjectionExpression origin , IReadOnlyList < string > tags )
112+ {
113+ var currentProjection = origin ;
114+ foreach ( var tag in tags ) {
115+ var projector = currentProjection . ItemProjector ;
116+ var newDataSource = projector . DataSource . Tag ( tag ) ;
117+ var newItemProjector = new ItemProjectorExpression ( projector . Item , newDataSource , projector . Context ) ;
118+ currentProjection = currentProjection . Apply ( newItemProjector ) ;
119+ }
120+ return currentProjection ;
121+ }
122+
107123 private Materializer
108124 BuildMaterializer ( ProjectionExpression projection , IEnumerable < Parameter < Tuple > > tupleParameters )
109125 {
@@ -194,7 +210,7 @@ internal Translator(TranslatorContext context, CompiledQueryProcessingScope comp
194210 {
195211 this . compiledQueryScope = compiledQueryScope ;
196212 this . context = context ;
197- tagsEnabled = context . Domain . Configuration . TagsLocation != TagsLocation . Nowhere ;
213+ tagsEnabled = context . Domain . TagsEnabled ;
198214 }
199215 }
200216}
0 commit comments