【发布时间】:2019-06-30 00:05:55
【问题描述】:
我有以下安排,我加入 2 个表以从第二个表中检索描述列。
我将实体框架 6 与 Oracle 12c 一起使用
public IQueryable<TEntity> GetAll()
{
return this.dbSet.AsQueryable();
}
var fooQuery = fooRepo.GetAll();
var barQuery = barRepo.GetAll();
var joinedQuery =
fooQuery.Join(
barQuery,
fooObj => new { fooObj.comp_key_1, fooObj.comp_key_2, fooObj.comp_key_3 },
barObj => new { barObj.comp_key_1, barObj.comp_key_2, barObj.comp_key_3 },
(fooItem, barItem) => new {
fooItem.comp_key_1,
fooItem.comp_key_2,
fooItem.comp_key_3,
...
...
...
barItem.BarName
}
);
当执行代码时,它会生成以下 SQL,这不太理想,因为会生成一个意外的 where 子句。
SELECT
1 AS "C1",
"Extent1"."COMP_KEY_1" AS "COMP_KEY_1",
"Extent1"."COMP_KEY_2" AS "COMP_KEY_2",
"Extent1"."COMP_KEY_3" AS "COMP_KEY_3",
...
...
...
"Extent2"."BAR_NAME" AS "BAR_NAME"
FROM "FOO_TABLE" "Extent1"
INNER JOIN "BAR_TABLE" "Extent2" ON ("Extent1"."COMP_KEY_1" = "Extent2"."COMP_KEY_1") AND ("Extent1"."COMP_KEY_2" = "Extent2"."COMP_KEY_2") AND ("Extent1"."COMP_KEY_3" = "Extent2"."COMP_KEY_3")
WHERE ((("Extent2"."Discriminator" = N'Foo') OR ("Extent2"."Discriminator" = N'Bar')))
我错过了什么,需要做些什么来删除意外的 where 子句?
【问题讨论】:
标签: c# oracle linq entity-framework-6