我是一个缓存的查询,如下所示。
IQuery query = session.GetISession().CreateQuery(
@"from Table1 as ant
inner join fetch ant.Table2 Table2
left join fetch ant.Collection1 -- this is self join to table1
where ant.ExpDate is null
order by TAble2.DispOrder, ant.Col1, ant.Col2");
query.SetCacheable(true).SetCacheRegion("region1");
return query.List<Table1>()
在web.config
文件中设置缓存
<class-cache class="Table1" usage="nonstrict-read-write" region="Region1" />
<collection-cache collection="Table1.Collection1" usage="nonstrict-read-write" region="Region1" />
我在生成的日志中注意到,正如预期的那样,上面的查询执行了sql。但是,之后会为每个表和每一行单独执行sql(这是随机发生的)。
单个sql如下
select .... from table1 where id=1
select .... from table1 where id=2..... for all the unique ids of table1
select .... from table2 where id=1..... for all the unique ids of table2
and also for the left join
我不是为什么每个唯一ID都有查询的原因。