遇到一个问题,我希望上次导入数据以显示失败。我最终求助于 HQL,因为我必须执行两个查询,任何人都可以看到为什么这在 Linq to NHibernate 中不起作用(正确),这是 3.1 中的一个已知错误吗?
我要写的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);