我遇到了一些linq问题。我正在尝试获取一个对象列表,如果特定Id包含在我的ID列表中,则该对象列表会被删除。这是代码示例:
public IServiceResult<List<SurveyAnswer>> GetSurveyProjectSite(List<Guid>spsQsIds)
{
return this.Wrap(() =>
{
this.InspectionContext.Configuration.LazyLoadingEnabled = false;
List<SurveyProjectSiteQuestionResponse> response = new List<SurveyProjectSiteQuestionResponse>();
List<SurveyAnswer> answers = new List<SurveyAnswer>();
var newList = this.InspectionContext.SurveyProjectSiteQuestionResponses
.Include("SurveyAnswer")
.Where(x => spsQsIds.Contains(x.SurveyProjectSiteQuestionSetId));
response.AddRange(newList);
foreach (SurveyProjectSiteQuestionResponse r in response)
{
answers.Add(r.SurveyAnswer);
}
return answers;
});
}
类别:
public class SurveyProjectSiteQuestionResponse : IDentifiable<Guid>, IPushable, IPullable
{
[ProtoMember(1)]
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
[ProtoMember(2)]
public Guid SurveyProjectSiteQuestionSetId { get; set; }
[ForeignKey("SurveyProjectSiteQuestionSetId")]
public virtual SurveyProjectSiteQuestionSet SurveyProjectSiteQuestionSet { get; set; }
[ProtoMember(3)]
public long SurveyQuestionId { get; set; }
[ForeignKey("SurveyQuestionId")]
public virtual SurveyQuestion SurveyQuestion { get; set; }
[ProtoMember(4)]
public Guid SurveyAnswerId { get; set; }
[ForeignKey("SurveyAnswerId")]
public virtual SurveyAnswer SurveyAnswer { get; set; }
[ProtoMember(5)]
public long UserId { get; set; }
[ForeignKey("UserId")]
public virtual User User { get; set; }
[ProtoMember(6)]
[Required]
public DateTime ResponseDate { get; set; }
[ProtoMember(7)]
[Column(TypeName = "datetime")]
public DateTime ModifiedDate { get; set; }
}
Where()中存在问题。当我在其中包含Contains()时,我不会得到任何结果。我检查了我的Guids,我正在测试的实例有77个匹配。是否存在阻止Contains()在Where()中正常工作的内容。提前感谢您的帮助。