拥有IQueryOver,我如何从它获取行计数,而无需从DB加载所有行? QueryOver有RowCount()方法,但如果基础查询有组或不同,它会丢弃它们。从IQueryOver获取计数,无需从DB加载行
*****更新*****
SQL genearted为QueryOver.RowCount(正如你看到它丢弃DISTINCT):
exec sp_executesql N'
SELECT count(*) as y0_
FROM dbo.OPR_STL_DCM this_
left outer join dbo.OPR_STL_LN_ITM lineitem1_
on
this_.DCM_ID=lineitem1_.DCM_ID
left outer join dbo.OPR_STL_DY_LN_ITM daylineite2_
on
lineitem1_.DCM_ID=daylineite2_.DCM_ID and
lineitem1_.TND_ID=daylineite2_.TND_ID
WHERE
daylineite2_.BSNS_DT >= @p0 and
daylineite2_.BSNS_DT <= @p1'
,N'@p0 datetime,@p1 datetime',@p0='2016-07-22 00:00:00',@p1='2016-08-21 23:59:59'
和
为生成的SQL QueryOver:
exec sp_executesql N'
SELECT distinct this_.DCM_ID as y0_,
this_.RTL_STR_ID as y1_,
this_.WS_ID as y2_,
this_.BSNS_DT as y3_,
this_.OPR_ID as y4_,
this_.TND_RPSTY_ID as y5_,
this_.IS_CNC as y6_,
this_.IS_SNG_DY_STL as y7_,
this_.BGN_DT_TM as y8_,
this_.END_DT_TM as y9_
FROM dbo.OPR_STL_DCM this_
left outer join dbo.OPR_STL_LN_ITM lineitem1_
on
this_.DCM_ID=lineitem1_.DCM_ID
left outer join dbo.OPR_STL_DY_LN_ITM daylineite2_
on
lineitem1_.DCM_ID=daylineite2_.DCM_ID and
lineitem1_.TND_ID=daylineite2_.TND_ID
WHERE daylineite2_.BSNS_DT >= @p1 and
daylineite2_.BSNS_DT <= @p2'
,N'@p1 datetime,@p2 datetime',@p0=20,@p1='2016-07-22 00:00:00',@p2='2016-08-21 23:59:59'
正如你看到的,行数方法没有得到查询结果的实际计数! –