Retrieving content and all associated properties i

2019-08-11 06:32发布

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.

1条回答
\"骚年 ilove
2楼-- · 2019-08-11 06:45

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

查看更多
登录 后发表回答