You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
If there are 2 entities, where EntityA has a nullable foreign key to EntityB and EntityB has a nonnullable property, e.x an order number with type int, If there is a request which gets all EntityA objects with an orderBy of "EntityB/Order" and an expand for "EntityB" then the "Nullable object must have a value." exception gets thrown by ef core.
Reproduce steps
The following data is needed for reproduction. One EntityB object and 2 EntityA objects, one has the foreign key to EntityB set and the other has null instead.
Request/Response
Request: /odata/EntityA?$orderBy=EntityB/Order&$expand=EntityB($select=Id)
Response: None Exception is thrown and Stream gets cut off.
Expected behavior
The collection of EntityA should be returned as requested. It should order the collection and expand the EntityA navigation properties if they are not null.
Screenshots
None
Additional context
The request works correct if there is only the orderBy or the expand, but both in combination will throw an exception.
The request will work correctly as well when an nullable property is used in the orderBy clause.
This is a minimal viable reproduction project. You can trigger the requests from the "EfCoreNullableForeignKey.http" file. EfCoreNullableForeignKey.zip
The text was updated successfully, but these errors were encountered:
Assemblies affected
Microsoft.AspNetCore.OData: 9.1.3
Describe the bug
If there are 2 entities, where EntityA has a nullable foreign key to EntityB and EntityB has a nonnullable property, e.x an order number with type int, If there is a request which gets all EntityA objects with an orderBy of "EntityB/Order" and an expand for "EntityB" then the "Nullable object must have a value." exception gets thrown by ef core.
Reproduce steps
The following data is needed for reproduction. One EntityB object and 2 EntityA objects, one has the foreign key to EntityB set and the other has null instead.
Data Model
EDM (CSDL) Model
Request/Response
Request:
/odata/EntityA?$orderBy=EntityB/Order&$expand=EntityB($select=Id)
Response: None Exception is thrown and Stream gets cut off.
Expected behavior
The collection of EntityA should be returned as requested. It should order the collection and expand the EntityA navigation properties if they are not null.
Screenshots
None
Additional context
The request works correct if there is only the orderBy or the expand, but both in combination will throw an exception.
The request will work correctly as well when an nullable property is used in the orderBy clause.
This is a minimal viable reproduction project. You can trigger the requests from the "EfCoreNullableForeignKey.http" file.
EfCoreNullableForeignKey.zip
The text was updated successfully, but these errors were encountered: