Open robertrutkowski opened 6 months ago
@robertrutkowski When you use $select, by default only the select properties (maybe the key) are included in the final result. It's for perf and the purpose of $select.
So, in your scenario, you should customize the default Select binder to include the extra properties in the final result.
You can see my changes based on your repro at https://github.com/xuzhg/WebApiSample/blob/main/v8.x/OData.Annotations.Example/readme.md
Let us know any other questions.
Describe the bug I would like to add instance annotation to a property (
OwnerId
) by including an additional property (OwnerIdName
) as its value. This setup works as expected without using the$select
query option. However, when$select
is applied, theresourceContext.ResourceInstance
does not include theOwnerIdName
property, leading to a null reference error because theOwnerIdName
is not fetched and thus cannot be added as an instance annotation.I am seeking advice on how to ensure
OwnerIdName
is included as an instance annotation forOwnerId
when$select
is applied, or how to work around this issueCode I've created:
ODataSerializerProvider
andODataResourceSerializer
to provide custom serialization and add annotation.IEdmModel, where I add
OwnerIdName
as ignored property,Simple Controller to consume client request.
Below i've attached my codes, result without
$select
and error with$select
param. Additionally, i've also added codes to my repo.Result without
$select
param:Error with
$select
param (line23
in fileCustomODataResourceSerializer.cs
):