我有一个LINQ查询,尝试在oracle 11g上执行它。 相同的查询在12c上执行完全正常,但它在11g上给出了以下错误。
ORA-00904: "Extent1"."ID": invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
以下是生成的SQL。只显示给出错误的查询的特定部分,
SELECT
"Extent1".ID,
(
SELECT "top".ADMIT_DATE
FROM
(
SELECT "Project7".ADMIT_DATE
FROM ( SELECT "Extent7".ADMIT_DATE FROM SYS.Table2 "Extent7" WHERE "Extent1".ID = "Extent7".ID )"Project7"
ORDER BY "Project7".ADMIT_DATE ASC
) "top"
WHERE ( ROWNUM <= 1) AND ROWNUM <= 1
)
AS C1 FROM SYS.Table1 "Extent1";
有人可以解释11g中导致问题的原因!!此查询在12c上正常工作。
更新: 这是linq查询。 上面的SQL是这些linq查询生成的SQL的一部分。
var query = from p in context.Person
where p.Meetings.Any() &&
p.Vitals.Any(v => v.WT.HasValue && v.WT >= 20 && v.WT <= 300) &&
p.Detentions.Any(d => ((d.DX_TYPE != null && d.DX_TYPE == "09") || (d.DX_TYPE == null && "09" == null)) && d.DX.StartsWith("V") && d.DX != null) &&
p.Meetings.Any(meet => meet.Detentions.Any(d => ((d.DX_TYPE != null && d.DX_TYPE == "09") || (d.DX_TYPE == null && "09" == null)) && d.DX.StartsWith("250") && d.DX != null))
select new
{
p.HISPANIC,
p.RACE,
StudentID = p.PersonID,
AdmissionOn = p.Meetings.OrderBy(meet => meet.ADMIT_DATE).Select(meet => meet.ADMIT_DATE).FirstOrDefault(),
AdmissionYear = p.Meetings.OrderBy(meet => meet.ADMIT_DATE).Select(meet => meet.ADMIT_DATE).FirstOrDefault().Year,
AdmissionMonth = p.Meetings.OrderBy(meet => meet.ADMIT_DATE).Select(meet => meet.ADMIT_DATE).FirstOrDefault().Month
};
var g = query.GroupBy(k => new { Hispanic = k.HISPANIC, Race = k.RACE, AdmissionYear = k.AdmissionYear })
.Select(k => new { Hispanic = k.Key.Hispanic, Race = k.Key.Race, AdmissionYear = k.Key.AdmissionYear, Persons = k.Count() }).ToList();
答案 0 :(得分:2)
问题是Oracle 11g不支持多个查询深度引用标识符。 SQL Server(由Microsoft创建)确实支持这一点,这就是为什么你的LINQ工作正常,但Oracle服务器不喜欢SQL。
本质上,它是oracle提供程序工具中的一个错误,它不会将您的LINQ转换为版本11g的有效SQL。