更新1 92020年7月9日:至少有两个问题。对不起,我无法让编辑器正确设置文本格式。
-
字段名需要有一个字段。前缀
QueryBuilderqueryBuilder=QueryBuilder.New.FieldExists("fields.myurl&",true(.FieldEquals("fields.myurl","/"(;
-
似乎有必要迭代内容类型。
https://cdn.contentful.com/spaces/qjiunow8a0ig/entries?fields.myurl[exists]=true&fields.myurl=%2F
未处理的异常。Contentful.Core.Errors.ContentfulException:需要内容类型ID。查询条目和涉及字段时,需要将查询限制为特定的内容类型。请发送内容类型ID(而不是名称(作为URI查询参数";content_type";位于C:\temp\deliverystack\Contentful.Core\ContentfulClientBase.cs:line 142中的Contentful.Core.ContentfulClient Base.CreateExceptionForFailedRequest(HttpResponseMessage res(位于C:\temp\deliverystack\Contentful.Core\ContentfulClientBase.cs:line 320中的Contentful.Core.ContentfulClient Base.EnsureSuccessfulResult(HttpResponseMessage响应(位于C:\temp\deliverystack\Contentful.Core\ContentfulClientBase.cs:line 264中的Contentful.Core.ContentfulClient Base.SendHttpRequest(HttpRequestMessage请求,CancellationToken cancellionToken(位于C:\temp\deliverystack\ContentfulClientBase.SendHttpRequest(字符串url、HttpMethod方法、字符串authToken、CancellationToken取消令牌、HttpContent内容、可为空的
1 version, String contentTypeId, String organisationId, List
1 additionalHeaders(位于C:\temp\deliverystack\Contentful.Core\ContentfulClient.cs:line 654中的Contentful.Core.ContentfulClient.Get(字符串url,CancellationToken cancellionToken(位于C:\temp\deliverystack\Contentful.Core\ContentfulClient.cs:line 188中的Contentful.Core.ContentfulClient.GetEntries[T](字符串查询字符串,CancellationToken取消令牌(位于C:\temp\deliverystack\Contentful.Core\ContentfulClient.cs:line 171中的Contentful.Core.ContentfulClient.GetEntries[T](QueryBuilder`1 QueryBuilder,CancellationToken cancellionToken(在cfclt。C:\Program.Main(String[]args(在C:\temp\deliverystack\cfclt\Program.cs:line 33 中
所以这是有效的:
QueryBuilder<Entry> queryBuilder = QueryBuilder<Entry>.New.ContentTypeIs("firstContentType").FieldExists("fields.url", true).FieldEquals("fields.url", "/");
我想我会迭代内容类型并创建要查询的线程。
原始线程:
我想使用Contentful.NET SDK(https://www.contentful.com/developers/docs/net/)以实现web应用程序的内容传递层。
我的第一个问题是如何将传入的HTTP请求映射到Contentful中的条目,而不在内容传递层中存储任何相关配置。我想传递一个URL,让SDK返回一个适当类型的水合对象。
我在应该有URL的条目中放入了一个名为URL的文本字段。我想查询所有内容类型,以查找在该URL字段中具有特定值的任何条目。
我尝试了一些查询,但总是得到异常:
QueryBuilder<Entry> queryBuilder = QueryBuilder<Entry>.New.ContentTypeIs("firstContentType").FieldExists("url", true).FieldEquals("url", "/");
ContentfulCollection<Entry> entries = client.GetEntries(queryBuilder).GetAwaiter().GetResult();
Unhandled exception. Contentful.Core.Errors.ContentfulException: The query you sent was invalid. Probably a filter or ordering specification is not applicable to the type of a field.[
{
"name": "unknown",
"path": [
"url"
],
"details": "The path "url" is not recognized"
}
]
at Contentful.Core.ContentfulClientBase.CreateExceptionForFailedRequest(HttpResponseMessage res) in C:tempdeliverystackContentful.CoreContentfulClientBase.cs:line 142
at Contentful.Core.ContentfulClientBase.EnsureSuccessfulResult(HttpResponseMessage response) in C:tempdeliverystackContentful.CoreContentfulClientBase.cs:line 320
at Contentful.Core.ContentfulClientBase.SendHttpRequest(HttpRequestMessage request, CancellationToken cancellationToken) in C:tempdeliverystackContentful.CoreContentfulClientBase.cs:line 264
at Contentful.Core.ContentfulClientBase.SendHttpRequest(String url, HttpMethod method, String authToken, CancellationToken cancellationToken, HttpContent content, Nullable`1 version, String contentTypeId, String organisationId, List`1 additionalHeaders) in C:tempdeliverystackContentful.CoreContentfulClientBase.cs:line 257
at Contentful.Core.ContentfulClient.Get(String url, CancellationToken cancellationToken) in C:tempdeliverystackContentful.CoreContentfulClient.cs:line 654
at Contentful.Core.ContentfulClient.GetEntries[T](String queryString, CancellationToken cancellationToken) in C:tempdeliverystackContentful.CoreContentfulClient.cs:line 188
at Contentful.Core.ContentfulClient.GetEntries[T](QueryBuilder`1 queryBuilder, CancellationToken cancellationToken) in C:tempdeliverystackContentful.CoreContentfulClient.cs:line 171
我相对确信,在其URL字段中有一个值为/的firstContentType条目。我做错了什么?
为什么/怎么会这么难用无头CMS做这么基本的事情?看到这个;它就像一个兔子洞,我没有时间去探索。
https://www.contentfulcommunity.com/t/how-to-query-on-multiple-content-types/473/10
如果需要,我不介意迭代内容类型,但如果查询无论如何都不起作用,我不确定这是否值得?
您需要指定筛选字段的整个路径。因此.FieldExists("fields.url", true).FieldEquals("fields.url", "/")
应该做到这一点。