odata.net
odata.net copied to clipboard
$expand always generates left join
$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 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?
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 , 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!
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.
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.
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.
@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.
@Robelind Was this issue resolved?
Closing due to inactivity