我需要在oracle 11.2数据库中运行此查询,但生成的查询包含“OUTER APPLY”。我该如何解决?
var query = from r in Ctx.Reg
let status_1 = (r.Hist.OrderByDescending(o => o.Id).FirstOrDefault(h => h.RegId == r.Id).Status == 1)
let status_2 = (r.Hist.OrderByDescending(o => o.Id).Skip(1).FirstOrDefault(h => h.RegId == r.Id).Status == 2)
select new
{
r.Id,
...
status_1,
status_2
};
答案 0 :(得分:0)
OUTER APPLY
由您的let
语句表达式生成。您可以使用基于EXISTS
的等效LINQ结构将它们转换为Any
可翻译表达式来避免它:
var query = from r in Ctx.Reg
let status_1 = r.Hist.OrderByDescending(h => h.Id).Take(1).Any(h => h.Status == 1)
let status_2 = r.Hist.OrderByDescending(h => h.Id).Skip(1).Take(1).Any(h => h.Status == 2)
select new
{
r.Id,
...
status_1,
status_2
};
请注意,h.RegId == r.Id
不需要r.Hist
,因为{{1}}导航属性暗含了这一点。