Comments (14)
Yes, we should support enums as keys.
@gathogojr -- Note: that the code shown above as the current logic in the first block is slightly different than what I see in the repo.
In the repo, the conditional check is:
if (!PrimitiveType.IsKnownType(key.PropertyType) && !(key.PropertyType.GetGenericTypeDefinition() == typeof(System.Nullable<>) && key.PropertyType.GetGenericArguments().First().IsEnum()))
which is different than above reported code in that:
- the IsEnum check is on keyProperty.PropertyTypeGetGenericArguments().First().IsEnum(), rather than keyProperty.PropertyType.IsEnum()
- the IsEnum check is grouped with the GetGenericTypeDefinition() check rather than a separate check
I suspect the reason that the fixed code doesn't throw is not because of ordering, or even grouping, but because it doesn't call GetGenericArguments.
I'm not sure the rationale behind the existing logic that would make us think that an unknown type must be generic (or why we specifically check for an enum if it is), but if we don't know for sure that key.PropertyType is generic we should check IsGenericType before calling GetGenericTypeDefinition or GetGenericArguments.
from odata.net.
I'm also encountering the same issue when attempting to access the Microsoft Business Central API through OData V4. We're using the latest Microsoft.OData NuGet packages, 7.21.1. Any attempt to enumerate a collection with an enum key returns the error about generic types, even when trying to project to a new class.
from odata.net.
To expand on the above, it looks like the Business Central API converted quite a few string to Enums. The ItemReference class uses an Enum as a key field and we're getting the error in GetKeyProperties().
from odata.net.
@mikepizzo Yes the problem seems to be that GetGenericTypeDefinition is called too early. The code should accept simple types and enums as valid keys and reject generic types. So changing the ordering of the if statement ensures that GetGenericTypeDefinition isn't called if the key is an enum. Can we contribute on this issue by creating a pr to fix this?
from odata.net.
Any news on this?
We're having the same problem when using Odata together with Business Central
from odata.net.
We used a work around by selecting odatakeys and not selecting the enum key fields. https://www.cloudfronts.com/blog/d365-business-central/using-odatakeyfields-for-fetching-records-in-business-central-web-services/
from odata.net.
Sadly that isn't going to work for me.
I'm getting the error when running this code
var linesQuery = new DataServiceCollection<MtSalesInvoiceLine>(_mtApiContext.MtSalesInvoiceLines.AddQueryOption("$expand", "dimensionSetLines").Where(s => s.DocumentId == salesOrder.Id));
There's an enum key field somewhere in the hierarchy.
Will update when I find a solution though
from odata.net.
Found out my error was due to breaking changes being introduced on Business Centrals side with version "24.1.18927.19282". Running the same code towards an Business Central Cloud environment running "24.0.16410.17628" succeeds.
from odata.net.
@MikkelGlerup , do you have a link to the breaking change?
from odata.net.
@nmushovic I made my own issue and gave it more details here
EDIT:
I was wrong, it had nothing to do with version
from odata.net.
Hello, can someone to aprove this fix: #3013
It is critical because our app which communicates with MS Bussiness Central does not work after new API definition with enums was updated.
@gathogojr @habbes @xuzhg @ElizabethOkerio @paulodero
Thank you very much.
from odata.net.
from odata.net.
@mikepizzo It looks fine now.
from odata.net.
Do you know when a new version with a fix for this bug will be released?
from odata.net.
Related Issues (20)
- Package Microsoft.AspNetCore.OData 8.2.5 and OData 8 Previews HOT 1
- ODataConventionModelBuilder GetEdmModel Memory / Performance Problem HOT 6
- EdmTargetPath does not get parsed correctly if it contains a collection-valued NavigationProperty HOT 1
- ODataLib Client fails to deserialize payload with @odata.context relative URL starting with ../ HOT 3
- OData.Client 8 preview fails to translate navigation query HOT 3
- Feature gap: enable untyped for ODataResourceValue and ODataCollectionValue
- No ways to set instance annotation for top-level collection value HOT 3
- Business Central Cloud "24.1.18927.19282" breaking changes
- OData.Client DataServiceContext BulkUpdate() Always Uses Protocol Version 4.01 HOT 6
- Failure when posting a request with odata-version header equal 4.01 HOT 1
- Bad performance while using OData client vs using HttpClient on Android HOT 9
- Allow ignoring errors, like collection is null from server response HOT 4
- High CPU Odata Usage AddWithResize() HOT 3
- memory occupied and no longer released HOT 3
- OData Client supports nullable generic types for enums
- Batch requests for DataServiceActionQuery, DataServiceActionQuerySingle and DataServiceQuerySingle HOT 1
- Is there a way to update batch itemβs URL?
- OData8: No way to get top level annotation HOT 3
- EDMX validation fails over DTD HOT 4
- Client 8.0.0 - Projection fails for navigation property being null HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from odata.net.