[英]Association [values] was not found upon using Simple.OData.Client
我有一個通過IModelConfiguration配置的 OData 服務
public void Apply(ODataModelBuilder builder, ApiVersion apiVersion)
{
builder.EntitySet<ValuesContainer>("ValuesContainer");
builder.AddComplexType(typeof(ValueItem));
}
它產生以下(混淆並選擇相關部分)元數據:
<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>
基本上我有一個實體類型ValuesContainer ,它有一個復雜類型ValueItem的集合。
當我嘗試通過 http get 查詢服務時,以下示例工作正常:
~/odata/valuescontainer?$filter=values/any(v:v/value eq 'example')
此示例為我提供了任何包含示例值的ValuesContainer 。
然而,當我在另一個 C# 應用程序中使用Simple.OData.Client時,我收到錯誤Simple.OData.Client.UnresolvableObjectException: 'Association [values] not found'
我的 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);
我試圖通過 Fiddler 追蹤請求是否錯誤,但它發生在接收 OData 服務的元數據和處理表達式之間。
我注意到它在以下位置拋出異常
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;
}
...
}
}
它試圖將我的屬性Values作為NavigationProperty ,但它不是。
我的元數據和 OData 服務的配置是否錯誤,為什么它通過 http get 調用工作,或者是 Simple.OData.Client 的錯誤行為?
顯然 Simple.OData.Client 中存在一個錯誤,它要求集合具有NavigationProperty ,這是不正確的。
https://github.com/simple-odata-client/Simple.OData.Client/issues/274
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.