odata.net icon indicating copy to clipboard operation
odata.net copied to clipboard

$expand always generates left join

Open Robelind opened this issue 6 years ago • 8 comments

$expand generates left join even for optional foreign keys, which leads to that entities without a value for the foreign key aren't included in the result set.

Assemblies affected

Microsoft.AspNetCore.OData 7.0.1

Reproduce steps

Have an entity definition with an optional foreign key and a navigation property corresponding to the foreign key. Issue a request, http://<url>/<Controller>?$expand=<Navigation property>

Expected result

Entities without a value for the foreign key would be included in the result set.

Actual result

Entities without a value for the foreign key aren't included in the result set.

Robelind avatar Oct 31 '18 09:10 Robelind

@Robelind Not sure I understand your scenario. If you are trying to do $expand on an optional foreign key, shouldn't the entities w/o the key be not included in the result since the navigation links won't find the targets?

biaol-odata avatar Oct 31 '18 19:10 biaol-odata

if "Without a value" means the FK has a value, but the other row is not there - there is a bug open for this at EF Core, to be fixed in the 3.0 timeframe beginning next year.

If not, it STILL looks more like an EF Core issue.

NetTecture avatar Oct 31 '18 19:10 NetTecture

@NetTecture , thanks for the pointer. @Robelind , this does appear to be related to the IQueryable implementation and not OData. Please let us know if you are not using EF Core. Thanks!

madansr7 avatar Oct 31 '18 20:10 madansr7

Le me expand: EF Core = buggy as hell at the moment, with whole subsystems not usable (global filters) and standard sql broken (projection, null checks in lambdas). It is so bad, I apply a filter on query paths manually and if I find any of a number of issues, I load the whole stuff into memory and hand a materialized object tree to odata. And "any number of issues" right now runs down to "uses includes". Returning an EF query with a projection directly over to Odata = best way to get funny errors somewhere. Hope they fix that soon.

NetTecture avatar Nov 01 '18 07:11 NetTecture

My scenario is that the FK doesn't have a value, i.e. a nullable FK. I'd expect the query would use an outer join in this case and thus include entities which hasn't got a value for the FK. I'm using EF Core.

Robelind avatar Nov 01 '18 09:11 Robelind

Then you should make THAT case - which would include the EFCore documentation and a test case. Zero OData would be required. I think I read this issue somewhere recently - check the efcore bug log.

NetTecture avatar Nov 01 '18 10:11 NetTecture

@Robelind Same found here, Sucks - makes EF Core totally useless. No idea why that happens now. If you ahve a simple use case, can you upload the repro and link it at the similar bug I opened at https://github.com/aspnet/EntityFrameworkCore/issues/13883 ? That is the core issue that must be fixed, it seems.

NetTecture avatar Nov 07 '18 14:11 NetTecture

@Robelind Was this issue resolved?

KenitoInc avatar Aug 18 '22 10:08 KenitoInc

Closing due to inactivity

KenitoInc avatar Nov 20 '22 10:11 KenitoInc