Orchard - 以编程方式创建查询

时间:2013-03-19 21:53:37

标签: module orchardcms

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

由于IDependency接口的实现,我在我的Migrations.cs文件中这样做。

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

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

1 个答案:

答案 0 :(得分: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);