我有一个通过OData配置的IModelConfiguration服务
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方程“示例”)
这个例子给出了包含示例值的任何ValuesContainer。
然而,当我在另一个Simple.OData.Client.UnresolvableObjectException:应用程序中使用Simple.OData.Client时,我会得到错误的C#‘未找到关联值’
我的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;
}
...
}
}它试图以NavigationProperty的形式获取我的属性值,但它不是。
我的元数据和我的OData服务的配置是错误的吗?为什么它通过http调用工作,或者这是Simple.OData.Client的错误行为?
发布于 2020-02-12 09:28:43
显然,Simple.OData.Client中存在一个错误,它要求集合具有一个NavigationProperty,这是不正确的。
https://github.com/simple-odata-client/Simple.OData.Client/issues/274
https://stackoverflow.com/questions/60171793
复制相似问题