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

ODataClient.Internals.cs - AssertHasKey can not throw exception... #709

Open
NetTecture opened this issue Feb 9, 2020 · 3 comments
Open

Comments

@NetTecture
Copy link

...if the entity has no key requirement.

As per OData 4.01 it is valid to have an entity without key as contained entity that is unique - i.e. at the end of a :1 relationship.

This, i.e:

        var updatedResponse = await c.For<OdataApi.Event>()
            .Key(fetched.Identity)
            .NavigateTo<EventResponse>(x => x.Response)
            .Set(insertedResponse)
            .UpdateEntryAsync();

would update the Response navigation property on an Event class. This is a :1 relationship and marked as contained, and as such it does not have the requirement of a key.

Reference: http://docs.oasis-open.org/odata/new-in-odata/v4.01/new-in-odata-v4.01.pdf
Element 5.5: New: Key-Less Entity Types

Key properties of an entity type can now be part of a related entity type provided the navigation path to
the “remote” key property consists only of single-valued, non-nullable segments. And of course, these key
properties need an alias

Given that this is a runtime test, I am not sure it makes any sense to actually keep it.

Stack Trace:

Message:
Test method Tests.Api.Odata.Web.Controllers.EventTests.PostPutPatchResponse threw exception:
System.InvalidOperationException: No entry key specified.
Stack Trace:
RequestBuilder.AssertHasKey(FluentCommand command)
RequestBuilder.UpdateRequestAsync(Boolean resultRequired, CancellationToken cancellationToken)
ODataClient.UpdateEntryAsync(FluentCommand command, Boolean resultRequired, CancellationToken cancellationToken)
BoundClient`1.UpdateEntryAsync(Boolean resultRequired, CancellationToken cancellationToken)
EventTests.PostPutPatchResponse() line 270
ThreadOperations.ExecuteWithAbortSafety(Action action)

In this particular case, the check makes no sense and the patch chould be sent without a key for EventResponse.

@phatcher
Copy link
Collaborator

Do we know that an entity has no key from the metadata model - if so we can make it conditional

@NetTecture
Copy link
Author

We do.

Look at http://api.obb.tuev-daily.de/odata/$metadata

i.e.

This is a 1:1 relationship which is contained, so AccountProile per specs does NOT need a key.

It actually does not matter whether the ENTITY has a key or not.

As my code says:

var updatedResponse = await c.For<OdataApi.Event>()
.Key(fetched.Identity)
.NavigateTo(x => x.Response)

Here EventResponse is not a collection and there is a key for the Event. EventResponse actually has a key (for legacy reasons, pending removal), but you are not supposed to use it.

It alls dpends on the navigation. As I am moving from an entity with key throuh a :1 navigation property, a key is not needed because the object is uniquely identivied through the parent key and navigation property. The backend can / has to sort out which response is meant by using the key on the parent.

@phatcher
Copy link
Collaborator

Can I suggest you provide a patch then ;-)

Let me know if you need a hand

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

2 participants