-
Notifications
You must be signed in to change notification settings - Fork 159
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
Using $compute with ODataQueryOptions<T> not supported? #921
Comments
For ==> @mikepizzo ODL still needs the structural type to be 'open' type then we can use extra/dynamic properties on it. But, OData spec doesn't have such a limitation. Do you think it's time to change ODL behavior? For ==> @xuzhg This is an issue in non-odata scenarios containing dynamic properties. It's a bug and should fix it (@1) As a workaround, customer can customize the 'IPropertyMapper' to skip it, but there's no way for customer to cusotmize it on System.Text.Json. So, we need to fix it. ( @2 ) @blueghostuk Before the fix, here's a workaround.
2.a) Update the project as: <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.16" />
<PackageReference Include="Microsoft.AspNetCore.OData" Version="8.1.2" />
<PackageReference Include="Microsoft.AspNetCore.OData.NewtonsoftJson" Version="8.1.1" />
</ItemGroup> a.b) Create the following class. public class MyPropertyMapper : IPropertyMapper
{
public string MapProperty(string propertyName)
{
return propertyName;
}
}
builder.Services.AddControllers() .AddOData().AddODataNewtonsoftJson((model, structuredType) =>
{
return new MyPropertyMapper();
}); |
@blueghostuk Please take a look the fix at: #928. Thanks. |
Thanks for the quick fix! |
Discussed in #920
Originally posted by blueghostuk May 15, 2023
$compute does not seem to work when using
ODataQueryOptions<T>
. A simple example calculating the length of a string and selecting it.We are using EF Core, if I just pass $compute and $select, it fails with an error like:
Microsoft.OData.ODataException: Could not find a property named '{{propertyName}}' on type '{{entityType}}'.
If I also pass a $filter, I can see the SQL being generated but then fails with:
System.InvalidOperationException: Sequence contains no matching element at System.Linq.ThrowHelper.ThrowNoMatchException() at Microsoft.AspNetCore.OData.Query.Container.JsonPropertyNameMapper.MapProperty(String propertyName) at Microsoft.AspNetCore.OData.Query.Container.NamedProperty
1.ToDictionaryCore(Dictionary2 dictionary, IPropertyMapper propertyMapper, Boolean includeAutoSelected) at Microsoft.AspNetCore.OData.Query.Wrapper.SelectExpandWrapper.ToDictionary(Func
3 mapperProvider)at Microsoft.AspNetCore.OData.Query.Wrapper.SelectSomeConverter
1.Write(Utf8JsonWriter writer, SelectSome
1 value, JsonSerializerOptions options)`Example project here - https://github.com/blueghostuk/odata-compute-issue
Is there anything I am doing wrong? Or is this not supported?
The text was updated successfully, but these errors were encountered: