我有一个用EF4.4映射的现有Oracle数据库。当我试图从2个大子表中查询数据时。我收到的错误如下所示。我认为问题出在lambda查询中,但不确定它有什么问题。
表格
X
-XID
-VAL
A
-AID
BA
-BID
-AID
CA
-CID
-AID
BX
-BXID
-BID
-XID
CX
-CXID
-CID
-XID
查询:
var q = context.As.AsQueryable();
q = q.Where(o=>o.BAs.Any(p=>p.BX.Any(t=>t.BXID==1)))
.Union(
q.Where(o=>o.CAs.Any(p=>p.CX.Any(t=>t.CXID==1))).AsQueryable<A>();
生成的SQL:
SELECT
"Distinct1"."C1" AS "C1"
FROM ( SELECT DISTINCT
"UnionAll1"."AID" AS "C1",
FROM (SELECT
"Extent1"."AID" AS "AID"
FROM "SCHEMA"."A" "Extent1"
WHERE ( EXISTS (SELECT
1 AS "C1"
FROM ( SELECT
"Extent2"."BID" AS "BID"
FROM "SCHEMA"."BA" "Extent2"
WHERE ("Extent1"."AID" = "Extent2"."AID")
) "Project1"
WHERE ( EXISTS (SELECT
1 AS "C1"
FROM "SCHEMA"."BX" "Extent3"
WHERE (("Project1"."BID" = "Extent3"."BID") AND (1 = ( CAST(
"Extent3"."BXID" AS number(9,0)))))
))
))
UNION ALL
SELECT
"Extent4"."AID" AS "AID"
FROM "SCHEMA"."A" "Extent4"
WHERE ( EXISTS (SELECT
1 AS "C1"
FROM ( SELECT
"Extent5"."CID" AS "CID"
FROM "SCHEMA"."CA" "Extent5"
WHERE ("Extent4"."AID" = "Extent5"."AID")
) "Project5"
WHERE ( EXISTS (SELECT
1 AS "C1"
FROM "SCHEMA"."CX" "Extent6"
WHERE (("Project5"."CID" = "Extent6"."CID") AND (1 = ( CAST(
"Extent6"."CXID" AS number(9,0)))))
))
))) "UnionAll1"
) "Distinct1"
错误:
ORA-00904: "Extent1"."AID": invalid identifier