I have the following arrangement where I join 2 tables to retrieve a description column from the second table.
I am using Entity Framework 6 with 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
}
);
When executed the code it generates the following SQL which is less that ideal as there is an unintended where clause being generated.
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')))
What am I missing, what needs to be done to remove the unintended where Clause ?
Found it,
Had a base class for 'Bar' that contains only the p_key information and an extended class that contained all other properties.
Once I moved everything in to a single class
("Extent2"."Discriminator" = N'Foo') OR ("Extent2"."Discriminator" = N'Bar')
disappeared
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.