我将实体框架与 Oracle 刚刚发布的新 ODAC 一起使用。
我的问题是,我在以前的 beta 版本中工作的一些查询在这个新版本中停止工作。
这是一个例子:
IQueryable<SYS_PERFIL> query1 = m.DBContext.SYS_PERFIL.Where(T => T.SYS_UTILIZADOR.Where(TT => TT.ACTIVO == 1).Count() > 0);
IQueryable<SYS_PERFIL> query2 = m.DBContext.SYS_PERFIL.Where(T => T.SYS_UTILIZADOR.FirstOrDefault(TT => TT.ACTIVO == 1) != null);
string test1Query = ((System.Data.Objects.ObjectQuery)query1).ToTraceString();
string test2Query = ((System.Data.Objects.ObjectQuery)query2).ToTraceString();
var test1 = query1.ToList();
var test2 = query2.ToList();
当 test1 返回正确的结果时,test2 抛出一个 oracle 异常“ORA-00905:缺少关键字”,并显示消息:“Oracle 11.2.0.2.0 不支持 APPLY”。
我不想重新测试我所有的方法。有没有办法告诉EF不要使用apply?
以下是 EF 生成的查询:
测试1查询:
SELECT "Project1"."PERFIL_ID" AS "PERFIL_ID" FROM ( SELECT "Extent1"."PERFIL_ID" AS PERFIL_ID", (SELECT COUNT(1) AS "A1" FROM "SMI2012"."SYS_UTILIZADOR" "Extent2" WHERE (("Extent1"."PERFIL_ID" = "Extent2"."PERFIL_ID") AND (1 = "Extent2"."ACTIVO"))) AS "C1"
FROM "SMI2012"."SYS_PERFIL" "Extent1") "Project1" WHERE ("Project1"."C1" > 0)
测试2查询:
SELECT "Extent1"."PERFIL_ID" AS "PERFIL_ID" FROM "SMI2012"."SYS_PERFIL" "Extent1" CROSS APPLY (SELECT "Extent2"."PERFIL_ID" AS "PERFIL_ID", "Extent2"."ACTIVO" AS "ACTIVO", "Extent2"."USER_ID" AS "USER_ID" FROM "SMI2012"."SYS_UTILIZADOR" "Extent2" WHERE (("Extent1"."PERFIL_ID" = "Extent2"."PERFIL_ID") AND (1 = "Extent2"."ACTIVO")) AND (ROWNUM <= (1) ) ) "Element1" WHERE ("Element1"."USER_ID" IS NOT NULL)
提前致谢。