遇到問題,我希望上次導入的數據顯示失敗。我結束訴諸HQL,因爲我不得不執行兩個查詢任何人都可以看到爲什麼這不起作用(正確)在Linq到NHibernate,它是3.1中的已知錯誤?Get Max row(Linq,NHibernate)
我會寫的SQL。
select JobImport.* from
JobImportResult
inner join (
select Max(JobImportResultId) as JobImportResultId
from JobImportResult
group by JobImportId
)as tbl on tbl.JobImportResultId = JobImportResult.JobImportResultId
inner join JobImport on JobImport.JobImportId = JobImportResult.JobImportId
where ImportFailureReasonId is not null
HQL我結束了寫作。
select jir.JobImport from JobImportResult jir where jir.Id in
(select max(mjir.Id) from JobImportResult mjir group by mjir.JobImport)
and jir.ImportFailureReason is not null
LINQ的的作品(但我認爲2000年後行將打破)
var innerQuery = Query<JobImportResult>()
.GroupBy(jir=>jir.JobImport)
.Select(jir=>jir.Max(jr=>jr.Id));
var innerQueryListed = innerQuery.ToList();
var resultQuery = Query<JobImportResult>()
.Where(jir => innerQueryListed.Contains(jir.Id) && jir.ImportFailureReason != null)
.Select(jir => jir.JobImport);
LINQ的不工作:(
var innerQuery = Query<JobImportResult>()
.GroupBy(jir=>jir.JobImport)
.Select(jir=>jir.Max(jr=>jr.Id));
var resultQuery = Query<JobImportResult>()
.Where(jir => innerQuery.Contains(jir.Id) && jir.ImportFailureReason != null)
.Select(jir => jir.JobImport);
當你說它在2000行後中斷時,錯誤是什麼? – mattytommo 2012-04-11 07:45:20
FYI http://stackoverflow.com/questions/656167/hitting-the-2100-parameter-limit-sql-server-when-using-contains – Mark 2012-04-11 10:43:34
啊我不知道,我知道包含的是DEVIL上性能雖然嘿嘿:) – mattytommo 2012-04-11 10:49:01