Skip to content
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

ODataTypeInfo.cs not correctly identifying entity keys by "Id" #3052

Open
lawynn opened this issue Aug 31, 2024 · 1 comment
Open

ODataTypeInfo.cs not correctly identifying entity keys by "Id" #3052

lawynn opened this issue Aug 31, 2024 · 1 comment
Assignees

Comments

@lawynn
Copy link

lawynn commented Aug 31, 2024

ODataTypeInfo.cs is identifying conventional Id properties using case sensitive checking on "ID" which is failing for POCO classes that use Id.

Assemblies affected

Microsoft.OData.Client

Reproduce steps

Create an OData Entity with a POCO that doesn't have [Key] attributes, but uses an "Id" property (Casing matters, ID will work, id, or Id, or god forbid iD will fail).

At runtime do a standard query against a DataServiceContext that is bound to the service.

Note that the entity is not tracked in the context.

Any attempt to track the entity will result in an exception indicating that the entity type is invalid as it does not define a key.

Defining an Edm manually, and ensuring the .HasKey() is called does not resolve the issue as it seems that the Edm is not used in this check.

Expected result

The entity would be tracked conventionally using the Id as the key as there are no other keys defined, and the entity is a valid entity type in the edm.

Actual result

An exception is thrown indicating that the entity is not a valid entity type.

Additional detail

The proposed fix is to change the check the property names using case insensitive comparison. I think a better fix would be to use the provided EDM to determine the nature of the EntityTypes as they are correct in the ClientEdmModel when configured using the fluent apis.

#3050

@xuzhg
Copy link
Member

xuzhg commented Sep 3, 2024

FYI: OData.ModelBuilder uses the case insensitive:
https://github.com/OData/ModelBuilder/blob/main/src/Microsoft.OData.ModelBuilder/Conventions/EntityKeyConvention.cs#L51

@marabooy marabooy self-assigned this Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants