Orchardcms 创建筛选器而不是组筛选器

Orchardcms 创建筛选器而不是组筛选器,orchardcms,Orchardcms,我正在Orchard中创建一个自定义模块,我希望以编程方式创建一个查询 string queryName= "Product"; var item = _orchardServices.ContentManager.New("Query"); item.As<TitlePart>().Title =queryName; _orchardServices.ContentManager.Create(item, VersionOptions.Draft)

我正在Orchard中创建一个自定义模块,我希望以编程方式创建一个查询

    string  queryName= "Product";
    var item = _orchardServices.ContentManager.New("Query");
    item.As<TitlePart>().Title =queryName;
    _orchardServices.ContentManager.Create(item, VersionOptions.Draft);
    if (!item.Has<IPublishingControlAspect>() && !item.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable)
        _orchardServices.ContentManager.Publish(item);

    var queryPart = item.As<QueryPart>();
    queryPart.ContentItem.ContentType = queryName;
    string desc =" filter for the query";
    string contentType = "CommonPart.ChannelID.";
    var filterGroupRecord = new FilterGroupRecord();
    var filterRecord = new FilterRecord()
    {
        Category = "CommonPartContentFields",
        Type = contentType,
        Position = 0,
    };
    filterRecord.State = "<Form><Description>" + desc + "</Description><Operator>Equals</Operator><Value>ChannelId</Value></Form>";
    filterGroupRecord.Filters.Add(filterRecord);
    queryPart.FilterGroups.Insert(0, filterGroupRecord);
string queryName=“Product”;
var item=_orchardServices.ContentManager.New(“查询”);
item.As().Title=queryName;
_创建(item,VersionOptions.Draft);
如果(!item.Has()&&!item.TypeDefinition.Settings.GetModel().Draftable)
_orchardServices.ContentManager.Publish(项目);
var queryPart=item.As();
queryPart.ContentItem.ContentType=queryName;
string desc=“查询过滤器”;
string contentType=“CommonPart.ChannelID。”;
var filterGroupRecord=新的filterGroupRecord();
var filterRecord=新的filterRecord()
{
Category=“CommonPartContentFields”,
类型=内容类型,
位置=0,
};
filterRecord.State=”“+desc+“EqualsChannelId”;
filterGroupRecord.Filters.Add(filterRecord);
queryPart.FilterGroups.Insert(0,filterGroupRecord);
问题是:我想要设置查询的过滤器,而不是过滤器组。
你能告诉我如何改进我的代码吗?

数据库结构和类声明使之无法实现。你为什么需要它

更新:

我的意思是,您必须至少使用一个FilterGroupRecord。 但当查询发布时,若查询还并没有筛选组,那个么该筛选组将自动创建(请参阅QueryPartHandler)。您应该将筛选器添加到此组。不需要创建新组

var existingFilterGroup = queryPart.FilterGroups[0];
existingFilterGroup.Filters.Add(filterRecord);
更新2:


为了避免draftable查询出现问题(以及其他一些潜在问题),最好将调用Publish方法移动到代码的末尾,并且代码的其他部分应该保持不变。在您的情况下,如果您总是在不检查IPPublishingControlAspect和Draftable的情况下发布查询会更好。

您在说什么?为什么这是不可能的?如果我正确理解了TS希望在不使用FilterGroupRecord的情况下创建查询的问题,即直接向查询添加筛选器。是吗?我不这么认为,不。请看他在果园上的交叉张贴问题:请在交叉张贴时提供链接。这样: