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

Fix Cannot Attach Entity to DataServiceContext if Entity Key is an Enum #3106

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

WanjohiSammy
Copy link
Contributor

Issues

This pull request fixes #3080.

Description

This change is to add EdmValueKind.Enum case in ToClrValue in order to be able to get the Value property of the IEdmEnumValue. This means that when the edmValue is of type EdmValueKind.Enum, the method will return the underlying value of the enum instead of throwing the below exception:

Microsoft.OData.ODataException: A value with primitive kind 'Enum' cannot be converted into a primitive object value.
   at Microsoft.OData.Client.EdmValueUtils.ToClrValue(IEdmPrimitiveValue edmValue)
   at Microsoft.OData.Client.DataServiceUrlKeyDelimiter.<>c__DisplayClass9_0`1.<AppendKeyExpression>b__0(T p)
   at Microsoft.OData.Client.KeySerializer.GetKeyValueAsString[TProperty](Func`2 getPropertyValue, TProperty property, LiteralFormatter literalFormatter)
   at Microsoft.OData.Client.KeySerializer.AppendKeyWithParentheses[TProperty](StringBuilder builder, ICollection`1 keyProperties, Func`2 getPropertyName, Func`2 getPropertyValue)
   at Microsoft.OData.Client.DataServiceUrlKeyDelimiter.AppendKeyExpression(IEdmStructuredValue entity, StringBuilder builder)
   at Microsoft.OData.Client.ConventionalODataEntityMetadataBuilder.ConventionalODataUriBuilder.BuildEntityInstanceUri(Uri baseUri, IEdmStructuredValue entityInstance)
   at Microsoft.OData.Client.DataServiceContext.AttachTo(String entitySetName, Object entity, String etag)

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

@WanjohiSammy WanjohiSammy merged commit 712f07e into main Nov 7, 2024
5 checks passed
@WanjohiSammy WanjohiSammy deleted the fix/3080-cannot-attach-key-enum branch November 13, 2024 13:19
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

Successfully merging this pull request may close these issues.

Cannot Attach Entity to DataServiceContext if Entity Key is an Enum
3 participants