I'm trying to build a query that performs eager loading to avoid a lot of selects but when I try the following code:
RefrigeratorType typeAlias = null;
Refrigerator refAlias = null;
var refrigerators = this.UnitOfWork.CurrentSession.QueryOver<Refrigerator>(() => refAlias)
.Fetch(x => x.Type).Eager
.OrderBy(() => refAlias.Type).Asc
.ThenBy(() => refAlias.BTUs).Asc
.SelectList(
list => list
.SelectGroup(() => refAlias.Type)
.SelectGroup(() => refAlias.BTUs)
.SelectCount(() => refAlias.BTUs)
)
.List<object[]>();
Followed by this other queries that just what I want to avoid by using the Fetch() method:
-- statement #1
SELECT refrigerat0_.RefrigeratorTypeId as Refriger1_12_0_,
refrigerat0_.Name as Name12_0_,
refrigerat0_.Status as Status12_0_,
refrigerat0_.Description as Descript4_12_0_,
refrigerat0_.ImagePath as ImagePath12_0_
FROM RefrigeratorTypes refrigerat0_
WHERE refrigerat0_.RefrigeratorTypeId = 101 /* @p0 */
-- statement #2
SELECT refrigerat0_.RefrigeratorTypeId as Refriger1_12_0_,
refrigerat0_.Name as Name12_0_,
refrigerat0_.Status as Status12_0_,
refrigerat0_.Description as Descript4_12_0_,
refrigerat0_.ImagePath as ImagePath12_0_
FROM RefrigeratorTypes refrigerat0_
WHERE refrigerat0_.RefrigeratorTypeId = 102 /* @p0 */
-- statement #3
SELECT refrigerat0_.RefrigeratorTypeId as Refriger1_12_0_,
refrigerat0_.Name as Name12_0_,
refrigerat0_.Status as Status12_0_,
refrigerat0_.Description as Descript4_12_0_,
refrigerat0_.ImagePath as ImagePath12_0_
FROM RefrigeratorTypes refrigerat0_
WHERE refrigerat0_.RefrigeratorTypeId = 103 /* @p0 */
-- statement #4
SELECT refrigerat0_.RefrigeratorTypeId as Refriger1_12_0_,
refrigerat0_.Name as Name12_0_,
refrigerat0_.Status as Status12_0_,
refrigerat0_.Description as Descript4_12_0_,
refrigerat0_.ImagePath as ImagePath12_0_
FROM RefrigeratorTypes refrigerat0_
WHERE refrigerat0_.RefrigeratorTypeId = 104 /* @p0 */
-- statement #5
SELECT refrigerat0_.RefrigeratorTypeId as Refriger1_12_0_,
refrigerat0_.Name as Name12_0_,
refrigerat0_.Status as Status12_0_,
refrigerat0_.Description as Descript4_12_0_,
refrigerat0_.ImagePath as ImagePath12_0_
FROM RefrigeratorTypes refrigerat0_
WHERE refrigerat0_.RefrigeratorTypeId = 105 /* @p0 */
I'm using the the class follow as this:
public class Refrigerator : Product
{
public virtual int BTUs { get; set; }
public virtual RefrigeratorType Type { get; set; }
public virtual RefrigeratorTechnology Technology { get; set; }
}