检索Orchard CMS中的内容和所有相关属性[英] Retrieving content and all associated properties in Orchard CMS

本文是小编为大家收集整理的关于检索Orchard CMS中的内容和所有相关属性的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

有没有一种以编程方式从 Orchard 拉回内容项列表的好方法?

目前我正在这样做,它返回一个 ContentPartRecord 和标题,但无论如何它都不漂亮:

public IEnumerable<LookupViewModel> Lookup(string searchText)
    {
        var items = _contentManager
            .Query<MyItemPart, MyItemPartRecord>()
            .Join<TitlePartRecord>()
            .Where(x => x.Title.Contains(searchText))
            .OrderBy(x => x.Title)
            .List();
        return items
            .Select(x => new LookupViewModel()
            {
                Text = x.Name,
                Value = x.Id.ToString()
            });
    }

任何指向相关文档的指针都将不胜感激,Orchard 在这方面几乎没有.

推荐答案

不惜一切代价避免使用 Contains.它会表现得很糟糕.而是利用搜索模块.

本文地址:https://www.itbaoku.cn/post/1557098.html

问题描述

Is there a good way of programmatically pulling back a list of Content Items from Orchard?

At the moment I'm doing this, which returns a ContentPartRecord and the Title, but it's not pretty by any means:

public IEnumerable<LookupViewModel> Lookup(string searchText)
    {
        var items = _contentManager
            .Query<MyItemPart, MyItemPartRecord>()
            .Join<TitlePartRecord>()
            .Where(x => x.Title.Contains(searchText))
            .OrderBy(x => x.Title)
            .List();
        return items
            .Select(x => new LookupViewModel()
            {
                Text = x.Name,
                Value = x.Id.ToString()
            });
    }

Any pointers to related documentation would be greatly appreciated, there's very little in this regard for Orchard.

推荐答案

Avoid Contains at all costs. It will perform horribly. Instead, leverage the Search module.