我正在尝试仅选择受访者已完成的某些预筛选,但无法使用我的代码这样做。
代码:
IEnumerable<PreScreener> testin = new List<PreScreener>();
for (int i = 0; i < respondent.PreScreenerResponses.Count; i++)
{
testin = project.PreScreeners.Where(x => x.Id == respondent.PreScreenerResponses[i].PreScreenerId);
}
楷模:
public class PreScreener : IHasId, IHasProjectId
{
public int? Id { get; set; }
public int? ProjectId { get; set; }
public string ExternalId { get; set; }
public string Name { get; set; }
public int? PartialCount { get; set; }
public int? DisqualifiedCount { get; set; }
public int? CompleteCount { get; set; }
public DateTime? CreatedOn { get; set; }
public DateTime? UpdatedOn { get; set; }
public List<PreScreenerQuestion> Questions { get; set; }
}
public class PreScreenerResponse : IHasId, IHasProjectId
{
public int? Id { get; set; }
public int? ProjectId { get; set; }
public int? PreScreenerId { get; set; }
public int? RespondentId { get; set; }
public string Ip { get; set; }
public DateTime SubmittedDate { get; set; }
public DateTime CreatedOn { get; set; }
public double? Latitude { get; set; }
public double? Longitude { get; set; }
public Dictionary<short, PreScreenerQuestionResponse> Response { get; set; }
}
Respondent.PreScreenerResponses[i] <--Prescreeners 对 Prescreeners 的响应 Project.PreScreeners[i] <-- 属于该项目的所有 Prescreeners
我只是想将所有预筛选者放入一个列表中,该列表还将包括受访者的回复。我想我会创建一个新列表,然后将两个不同的列表组合起来,但是我选择的地方不起作用我总是得到一个空的测试列表。
基于响应编辑的代码:
我试过这个无济于事
IEnumerable<PreScreener> testin = new List<PreScreener>();
testin = project.PreScreeners.Where(p => respondent.PreScreenerResponses
.Select(r => r.PreScreenerId)
.Contains(p.Id));
有效的答案在下面打勾!!!