首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在使用Simple.OData.Client时找不到关联[值]

在使用Simple.OData.Client时找不到关联[值]
EN

Stack Overflow用户
提问于 2020-02-11 15:01:51
回答 1查看 1.1K关注 0票数 0

我有一个通过OData配置的IModelConfiguration服务

代码语言:javascript
复制
public void Apply(ODataModelBuilder builder, ApiVersion apiVersion)
{
     builder.EntitySet<ValuesContainer>("ValuesContainer");
     builder.AddComplexType(typeof(ValueItem));
}

它产生以下元数据(混淆并选择了相关部分):

代码语言:javascript
复制
<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代码:

代码语言:javascript
复制
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服务的元数据和处理表达式之间。

我注意到它在下面的位置抛出一个异常

代码语言:javascript
复制
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的错误行为?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-12 09:28:43

显然,Simple.OData.Client中存在一个错误,它要求集合具有一个NavigationProperty,这是不正确的。

https://github.com/simple-odata-client/Simple.OData.Client/issues/274

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60171793

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档