方法' Union'不受支持。声明类型:System.Linq.Queryable(C#)

时间:2016-10-17 15:00:30

标签: c# linq union concat iqueryable

我需要合并两个IQueryables。这是我的代码:

IQueryable<SearchResultsItem> resourceQueriable = GetIndexQueriable(ResourceIndexName);
IQueryable<SearchResultsItem> resourceQueriableResults = resourceQueriable.Where(x => x.DatabaseName == Database);

IQueryable<SearchResultsItem> resourcePageQueriable = GetIndexQueriable(ResourcePageIndexName);
IQueryable<SearchResultsItem> resourcePageQueriableResults =
    resourcePageQueriable.Where(x => x.DatabaseName == Database);

string ResourceTypeGuid = ItemReference.ItemReference.BBB_ResourceTypes_ProductGuide.InnerItem.ID.ToString().ConvertToShortId();

resourceQueriableResults = resourceQueriableResults.Where(x => x.ResourceType == ResourceTypeGuid);
resourcePageQueriableResults = resourcePageQueriableResults.Where(x => Boolean.Parse(x.IncludeInGuides));

IQueryable<SearchResultsItem> concatResults = resourceQueriableResults.Union(resourcePageQueriableResults);

IEnumerable<KeyValuePair<string, string>> namePathPairs =
    concatResults
        .Where(x => x.DatabaseName == Database)
        .OrderBy(y => y.NavTitle)
        .ToList() //Enumerate the query before translating it.
        .Select(x => new KeyValuePair<string, string>(x.NavTitle.CleanNavTitle(), x.Url));

return namePathPairs;

错误发生在IEnumerable<KeyValuePair<string, string>> namePathPairs = concatResults....

为什么会抛出此错误,如何合并我的两个IQueryables?我之前只有一个IQueryable,这很好用

IEnumerable<KeyValuePair<string, string>> namePathPairs =
            resourceQueriable
                .Where(x => x.DatabaseName == Database)
                .OrderBy(y => y.NavTitle)
                .ToList() //Enumerate the query before translating it.
                .Select(x => new KeyValuePair<string, string>(x.NavTitle.CleanNavTitle(), x.Url));

但是现在我在该行上使用了合并的IQueryable,它无法正常工作。

0 个答案:

没有答案