Giter Club home page Giter Club logo

Comments (14)

mikepizzo avatar mikepizzo commented on September 18, 2024

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:

  1. the IsEnum check is on keyProperty.PropertyTypeGetGenericArguments().First().IsEnum(), rather than keyProperty.PropertyType.IsEnum()
  2. 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.

kyleweishaupt avatar kyleweishaupt commented on September 18, 2024

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.

nmushovic avatar nmushovic commented on September 18, 2024

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().

image

from odata.net.

biboller avatar biboller commented on September 18, 2024

@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.

MikkelGlerup avatar MikkelGlerup commented on September 18, 2024

Any news on this?
We're having the same problem when using Odata together with Business Central

from odata.net.

nmushovic avatar nmushovic commented on September 18, 2024

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.

MikkelGlerup avatar MikkelGlerup commented on September 18, 2024

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.

MikkelGlerup avatar MikkelGlerup commented on September 18, 2024

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.

nmushovic avatar nmushovic commented on September 18, 2024

@MikkelGlerup , do you have a link to the breaking change?

from odata.net.

MikkelGlerup avatar MikkelGlerup commented on September 18, 2024

@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.

martinfbluesoftcz avatar martinfbluesoftcz commented on September 18, 2024

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.

mikepizzo avatar mikepizzo commented on September 18, 2024

from odata.net.

martinfbluesoftcz avatar martinfbluesoftcz commented on September 18, 2024

@mikepizzo It looks fine now.

from odata.net.

martinBluesoft avatar martinBluesoft commented on September 18, 2024

Do you know when a new version with a fix for this bug will be released?

from odata.net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.