Fetching not performed when using QueryOver<T>().Fetch()

19 views
Skip to first unread message

cidico

unread,
Sep 1, 2011, 9:02:46 AM9/1/11
to nhu...@googlegroups.com
Hello,

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[]>();

I get this sql queries:

SELECT   this_.TypeId      as y0_,
         this_.BTUs        as y1_,
         count(this_.BTUs) as y2_
FROM     Refrigerators this_
         inner join Products this_1_
           on this_.RefrigeratorId = this_1_.ProductId
GROUP BY this_.TypeId,
         this_.BTUs
ORDER BY this_.TypeId asc,
         this_.BTUs asc

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; }
}

The mapping is made by confORM and is like this:

mapper.Class<Refrigerator>(ca =>
{
ca.ManyToOne<RefrigeratorType>(prop => prop.Type, map =>
{
map.Cascade(Cascade.None);
map.Fetch(FetchKind.Join);
map.Lazy(LazyRelation.NoLazy);
}
);
}
);

What Am I doing wrong here?

Thanks in advance by any help provided!

Reply all
Reply to author
Forward
0 new messages