Reputation: 87
I have an OData service configured via an IModelConfiguration
public void Apply(ODataModelBuilder builder, ApiVersion apiVersion)
{
builder.EntitySet<ValuesContainer>("ValuesContainer");
builder.AddComplexType(typeof(ValueItem));
}
Which produces the following (obfuscated and selected the relevant parts) metadata:
<Edmx xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" Version="4.0">
<DataServices>
<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="MyProject.Api.Models">
<EntityType Name="ValuesContainer">
<Key>
<PropertyRef Name="id" />
</Key>
<Property Name="values" Type="Collection(MyProject.Api.Models.ValueItem)" />
<Property Name="id" Type="Edm.Guid" Nullable="false" />
</EntityType>
<ComplexType Name="ValueItem">
<Property Name="value" Type="Edm.String" />
<Property Name="id" Type="Edm.Guid" Nullable="false" />
</ComplexType>
</Schema>
</DataServices>
</Edmx>
Basically I have an entity type ValuesContainer which has a collection of a complex type ValueItem.
Following example works fine when I try to query the service via http get:
~/odata/valuescontainer?$filter=values/any(v:v/value eq 'example')
This example gives me any ValuesContainer which has a value containing example.
Yet, when I use Simple.OData.Client in another C# application, I get the error Simple.OData.Client.UnresolvableObjectException: 'Association [values] not found'
Code of my Simple.OData.Client:
var httpClient = _httpClientFactory.CreateClient();
var odataClientSettings = new ODataClientSettings(httpClient)
{
BaseUri = new Uri($"{_myEndPointConfig.BaseUrl}/odata/")
};
var entries = await new ODataClient(odataClientSettings).For<ValuesContainer>("ValuesContainer")
.Filter(x => x.Values.Any(v => v.value == "example").FindEntriesAsync().ConfigureAwait(false);
I tried to trace it down via Fiddler whether the request was bad, but it happens somewhere between receiving the metadata of the OData service and processing the expression.
I noticed it throws an exception at following location
namespace Simple.OData.Client.V4.Adapter
{
public class Metadata : MetadataBase {
...
private IEdmNavigationProperty GetNavigationProperty(string collectionName, string propertyName)
{
var property = GetEntityType(collectionName).NavigationProperties()
.BestMatch(x => x.Name, propertyName, NameMatchResolver);
if (property == null)
// obviously being thrown here
throw new UnresolvableObjectException(propertyName, $"Association [{propertyName}] not found");
return property;
}
...
}
}
It's trying to get my property Values as a NavigationProperty, but it isn't one.
Is my metadata and thus configuration of my OData service wrong and why is it working via a http get call, or is this misbehaviour of Simple.OData.Client?
Upvotes: 0
Views: 1712
Reputation: 87
Apparently there is a bug in Simple.OData.Client which demands collections to have a NavigationProperty, which is not correct.
https://github.com/simple-odata-client/Simple.OData.Client/issues/274
Upvotes: 0