Like the title says, why does the following call in code, create the below SQL?
CODE:
Code:
Session.Linq<Shipment>().Where(x => x.Id == id).FirstOrDefault();
SQL:
Code:
SELECT TOP 1 Id17_0_,
Reference17_0_,
Contract3_17_0_,
SAPNumber17_0_,
GoodsQua5_17_0_,
GoodsDes6_17_0_,
Coordina7_17_0_,
Client8_17_0_,
formula2_0_
FROM
(
SELECT ROW_NUMBER ( ) OVER ( ORDER BY __hibernate_sort_expr_0__ ) as
row,
query.Id17_0_,
query.Reference17_0_,
query.Contract3_17_0_,
query.SAPNumber17_0_,
query.GoodsQua5_17_0_,
query.GoodsDes6_17_0_,
query.Coordina7_17_0_,
query.Client8_17_0_,
query.formula2_0_,
query.__hibernate_sort_expr_0__
FROM
(
SELECT this_.Id as Id17_0_,
this_.Reference as Reference17_0_,
this_.ContractType as Contract3_17_0_,
this_.SAPNumber as SAPNumber17_0_,
this_.GoodsQuantity as GoodsQua5_17_0_,
this_.GoodsDescription as GoodsDes6_17_0_,
this_.Coordinator_User_Id as Coordina7_17_0_,
this_.Client_id as Client8_17_0_,
(
select count ( * )
from Comment_Contract
where Comment_Contract.Contract_id = this_.Id
) as formula2_0_,
CURRENT_TIMESTAMP as __hibernate_sort_expr_0__
FROM [Contract] this_
WHERE this_.Id = 6 /* @p0 */
) query
) page
WHERE page.row > 0
ORDER BY __hibernate_sort_expr_0__
I'm talking specifically about the "TOP 1" and the paging nested-selects. I'm trying to add some FetchType="Joins" to my mappings, but the TOP 1 is preventing that from working
Do I have some other code elsewhere which is likely to be causing this? If so, what is it likely to be so i can hunt it down. If not, what can i do to prevent it?
Something like this is what i'd expect (want) to be run:
Code:
SELECT this_.Id as Id17_0_,
this_.Reference as Reference17_0_,
this_.ContractType as Contract3_17_0_,
this_.SAPNumber as SAPNumber17_0_,
this_.GoodsQuantity as GoodsQua5_17_0_,
this_.GoodsDescription as GoodsDes6_17_0_,
this_.Coordinator_User_Id as Coordina7_17_0_,
this_.Client_id as Client8_17_0_,
(
select count ( * )
from Comment_Contract
where Comment_Contract.Contract_id = this_.Id
) as formula2_0_,
CURRENT_TIMESTAMP as __hibernate_sort_expr_0__
FROM [Contract] this_
WHERE this_.Id = 6 /* @p0 */
Thanks,
Andrew