1

我正在 Orchard 中创建一个自定义模块。启用模块后,我想以编程方式创建查询。

由于 IDependency 接口的实现,我在 Migrations.cs 文件中执行此操作。

我能够创建查询,但我是否以编程方式设置该查询的过滤器?

var announcementsQuery = _contentManager.Create("Query");
announcementsQuery.As<TitlePart>().Title = "Announcements";
_contentManager.Publish(announcementsQuery);
4

1 回答 1

2

我发现了如何做到这一点:

var announcementsQuery = _contentManager.Create("Query");
                announcementsQuery.As<TitlePart>().Title = "Announcements";
                announcementsQuery.As<QueryPart>().ContentItem.ContentType = "Announcement";
                var filterGroupRecord = new FilterGroupRecord();
                var filterRecord = new FilterRecord()
                    {
                        Category = "Content",
                        Type = "ContentTypes",
                        Description = "Announcement",
                        Position = 1,
                        State = "<Form><Description>Announcement</Description><ContentTypes>Announcement</ContentTypes></Form>"
                    };
                filterGroupRecord.Filters.Insert(0, filterRecord);
                announcementsQuery.As<QueryPart>().FilterGroups.Insert(0, filterGroupRecord);
于 2013-03-20T04:00:15.263 回答