Skip to content

Commit 76ca563

Browse files
Gunnar Liljasgliljas
Gunnar Liljas
authored andcommitted
Unit and partial fix for NH2504
1 parent 5e3f957 commit 76ca563

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/NHibernate.Test/Linq/QueryCacheableTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,36 @@ public void CacheableRegionBeforeOtherClauses()
114114
Assert.That(Sfi.Statistics.QueryCachePutCount, Is.EqualTo(2));
115115
Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(1));
116116
}
117+
118+
[Test]
119+
public void GroupByQueryIsCacheable()
120+
{
121+
Sfi.Statistics.Clear();
122+
Sfi.QueryCache.Clear();
123+
124+
var c = db
125+
.Customers
126+
.GroupBy(x => x.Address.Country)
127+
.Select(x => x.Key)
128+
.Cacheable()
129+
.ToList();
130+
131+
c = db
132+
.Customers
133+
.GroupBy(x => x.Address.Country)
134+
.Select(x => x.Key)
135+
.ToList();
136+
137+
c = db
138+
.Customers
139+
.GroupBy(x => x.Address.Country)
140+
.Select(x => x.Key)
141+
.Cacheable()
142+
.ToList();
143+
144+
Assert.That(Sfi.Statistics.QueryExecutionCount, Is.EqualTo(2));
145+
Assert.That(Sfi.Statistics.QueryCachePutCount, Is.EqualTo(1));
146+
Assert.That(Sfi.Statistics.QueryCacheHitCount, Is.EqualTo(1));
147+
}
117148
}
118149
}

src/NHibernate/Linq/GroupBy/AggregatingGroupByRewriter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public static class AggregatingGroupByRewriter
3838
typeof (AnyResultOperator),
3939
typeof (AllResultOperator),
4040
typeof (TimeoutResultOperator),
41+
typeof (CacheableResultOperator)
4142
};
4243

4344
public static void ReWrite(QueryModel queryModel)

0 commit comments

Comments
 (0)