-
Notifications
You must be signed in to change notification settings - Fork 477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OData Complex type in navigation property is null when expanded #1887
Comments
@Discjoggy I have gotten it added to the backlog since I was not able to spare time to figure out the issue. Someone will pick this up before the next release. |
That's okay. Nice to hear that this will be fixed in the next release somehow. If you need some more information or a sample implementation, just let me know, I thought the information here and on Stackoverflow would be enough. |
A similar (but different) issue here: Entity Employee
Entity Assignment
Entity Jobprofile
Strangely, in my case when selecting an Employee and expanding the Assignments the following happens:
So the navigation property is null (and removed from result through a custom ODataSerializerProvider) but the complex type is filled properly:
When I drop the Jobprofile controller and the corresponding configuration, effectively making Jobprofile just a complex type instead of an entity, it does show up in the result. Making it pretty clear that at least the rest of the implementation seems to be in order. Also interesting: Issue wasn't happening before we did the migration to .NET Core but almost all OData configuration has been rewritten so not sure if that is related. Models, repositories, mapping and other classes are pretty much identical though (Update 2: was a change in here actually, see bottom of post). Also tried setting MaxExpansionDepth to 0 (and to 10) as someone suggested on SO, but that doesn't help. Any suggestions on what to try? Update: Ofcourse, just after posting this I realized that my query might be wrong. The query I was testing with:
New query which does expand all entities, related entities and complex properties properly:
Guess I will look into auto expanding Jobprofiles and OrganizationUnits. This seems to be working as a final result for now. No other configuration in the models or wherever was needed to get everything working:
Sorry for the long post ;) Also figured out what was happening in the old .NET Framework solution, where the expands appeared to be happening automatically: The team had 2 identical JobProfile classes and 2 identical OrganizationUnit classes in the codebase. One was acting as a complex type and the other was registered as an entity. Nasty. |
Hm... |
I have also encountered this issue. |
When using EF Core 3.1, this works as expected. Previously I tested it with 2.1 |
We still see this issue with EF Core 3.1 and Microsoft.AspNet.OData. |
I am getting this same issue, but with complex properties & owned entities when I expand a navigation property and include a skip or top, even if skip is zero and top is not. When a skip and/or top is included EFC returns either a null on the complex/owned property, or a default if one is set in the model. This happens even if I don't include a nested expand. EFCore 3.1.3 Expected Result (I'm only including first record, not within the value array): Click to expand
Actual result (I am only showing first record) Click to expand
Removing both skip and top results in the correct response Model (works the same regardless of if the [Owned] attribute is on the complex properties) Click to expand
|
The original issue has been fixed in EF Core 3.1 release. When projecting a type which contains owned types they are automatically included now. As for @joelmeaders repro code. I believe that the issue is similar to dotnet/efcore#18672 (which had quite a different variations of the same when projection is custom and then skip/take is applied). All of those have been fixed in EF Core 5.0 preview1 |
I am still seeing the original issue when using EF Core 3.1.5 and ASP.NET Core OData 7.4.1. It appears that owned entities, whilst clearly populated in the IQueryable as observed server-side, deserialize to null in the client. The comment of 11th May suggests this is fixed in the releases I am using. Is this definitely correct? |
@MonkeyTennis I am also still seeing the original issue with EF Core 3.1.5 and OData 7.4.1. My entity relationship is a little different in that I do not have an explicit owned as defined in the example
Would that affect the outcome? |
@xuzhg Do you have plans to solve this issue on some nightly build ? I am still seeing the issue using EF Core 3.1.5 and ASP.NET Core OData 7.4.1. http://localhost:5000/api/customers?$skip=0&$top=1&$expand=customerType($select=title) { |
I haven't looked at this for a while but did attempt the upgrade again, and got the same issue. The GET APIs that are experiencing the issue have a return type of this.Ok(SingleResult.Create(query)). I have not found a way of getting this to include owned types. However, I have also noticed that if I debug the method and force the Queryable within the SingleResult to be executed, the owned types ARE returned to the OData client. I've worked around this by changing the response to be this.Ok(entity) where entity is the executed LINQ query, making sure to Include (and ThenInclude) where necessary. Could the development team comment on this? Am I misusing SingleResult in some way or is there a bug here? |
Actually, this only fixes the issue where a single result is being returned. If an IQueryable is returned, the issue remains. I have isolated it to the following:
/Odata/Users('username')/Possessions Resulting in the following JSON:
/Odata/Users('username')/Possessions?$expand=PossessionDefinition Resulting in the following JSON:
I do not know why but the inclusion of $expand causes the issue to occur. Does this ring any bells with the development team? |
I am getting this same issue. I explained the situation in issue number 2562. |
OData complex types in navigation properties are always serialized as
null
when the navigation property gets expanded. I am using Entity Framework Core in conjunction with ASP.NET Core + OData.Assemblies affected
Reproduce steps
I have exactly the same issue as described on Stackoverflow. So this example is translated from there.
Expected result
The complex property
ShippingAddress
should NOT benull
when the navigation propertyOrder
gets expanded with the requestGET /Customers(1337)?$expand=Order
:Actual result
The complex property
ShippingAddress
is ALWAYSnull
when the navigation propertyOrder
gets expanded with the requestGET /Customers(1337)?$expand=Order
:Additional detail
As a workaround it is possible to explicitly request every property with
$select
likeGET /Customers(1337)?$expand=Order($select=Id,StreetAddress)
. Sadly$select=*
is not working.The text was updated successfully, but these errors were encountered: