从另一个列表中获取列表过滤器中的项目

时间:2014-03-28 10:49:33

标签: c#

我需要从列表中获取项目,但是从另一个id列表中过滤id。这是我的代码,我无法弄清楚问题。有什么帮助吗?

var lstStatus = new List<int> {(int) SurveyRequestConstants.EnumSurveyRequestStatus.Open,
            (int) SurveyRequestConstants.EnumSurveyRequestStatus.InProgress,
            (int) SurveyRequestConstants.EnumSurveyRequestStatus.OnHold};   
var surveyRequestList = SurveyRequestRepository.Queryable().AsEnumerable().ToList();
var surveyRequests = (from first in surveyRequestList
                      join second in lstStatus
                      on first.SurveyRequestStatus.Id equals second
                      select new ListItem(string.Format("{0} {1} {2}",  
                                                        first.Id.ToString(),
                                                        first.Tenant.TenantLabel, 
                                                        first.CreatedDate), 
                                                        first.Id.ToString())).ToList();

1 个答案:

答案 0 :(得分:0)

以下是根据lstStatus

中的项目过滤surveyRequestList的代码
var surveyRequests = surveyRequestList
.Where(x => lstStatus
.Any(y => y == x.Id))
.Select(x => new ListItem(string.Format("{0} {1} {2}",  
                                         first.Id.ToString(),
                                         first.Tenant.TenantLabel, 
                                         first.CreatedDate), 
                                         first.Id.ToString()));

希望这是你在找什么?