防止重复

时间:2018-07-25 12:10:37

标签: c# linq

select,其中orderby,take子句和toArray()重复,只有第一行是不同的。如何缩短这3个linq查询以避免重复?

我已经包含了用于返回模型视图的方法

Node

谢谢

1 个答案:

答案 0 :(得分:2)

您创建的方法将reads7reads24readsShared作为参数类型并返回结果:

IEnumerable<PopularArticle> Get(Dictionary<Guid, SOMETHING> variable)
{
    return articleService.GetArticlesFromGuidList(variable.Select(x => x.Key), wcagOnly: branding.StrictlyWCAG2Accessible, useCache: true)
        .Select(x => new PopularArticle() { Article = x, ArticleGuid = x.ArticleGUID })
        .Where(x => contentAdminTestingDataFilterService.AllowFirmAccess(x.Article.FirmRef, lexUser) && x.Article.RemoveDate != null)
        .OrderByDescending(x => variable[x.ArticleGuid])
        .Take(Records)
        .ToArray();
}

示例调用:

model.Read7DayDataSource = this.Get(reads7);