你如何在Lambda表达式中进行演员表演?

时间:2014-04-03 11:53:51

标签: c# asp.net linq

考虑到最后一个是我想要的,我在Select:

上收到错误
AwardsListViewModel viewModel = AwardListViewModel
{
     menuChild = repository
                   .menuChild
                   .Where(p => p.MenuParentAcronym == "Awards Processing" 
                               && p.IsActive == "True")
                   .OrderBy(c => c.DisplayOrder)
                   .Select(m => m.Description == "Awards Processing List")
};

错误是:无法将System.Linq.IQueryable<bool>类型转换为System.Collections.Generic.IEnumerable<AwardsSystem30.Domain.Entities.MenuChild>。存在显式转换(您是否错过了演员?)

我该如何施展?

2 个答案:

答案 0 :(得分:5)

我怀疑您的查询没有按预期执行 - 它会返回IQueryable<bool>。我猜测最后一个Select子句应该是Where,而不是按预期工作。

如果这是正确的,下面的代码应该可行(我将where位合并为一个)

AwardsListViewModel viewModel = AwardListViewModel
{
     menuChild = repository
                   .menuChild
                   .Where(p => p.MenuParentAcronym == "Awards Processing" 
                               && p.IsActive == "True")
                               && p.Description == "Awards Processing List")
                   .OrderBy(c => c.DisplayOrder)
};

答案 1 :(得分:-2)

您可以投射到列表。

AwardsListViewModel viewModel = AwardListViewModel
{
     menuChild = repository
                   .menuChild
                   .Where(p => p.MenuParentAcronym == "Awards Processing" 
                               && p.IsActive == "True")
                   .OrderBy(c => c.DisplayOrder)
                   .Select(m => m.Description == "Awards Processing List")
                   .ToList()
};