【问题标题】:Lambda expression where id in list of idsLambda 表达式 where id 在 id 列表中
【发布时间】:2015-02-02 13:50:05
【问题描述】:

我有 2 个列表

var listquestionold = db.tblExamQuetions.Where(p => p.QuetionExamId == oldexamid).ToList();
var listquestionnew = listquestionnew = db.tblExamQuetions.Where(p => p.QuetionExamId == examid ).ToList();
List<tblExamQuestionAnswers> listanswers = new List<tblExamQuestionAnswers>();

我怎样才能得到questionIdlistquestionold 中的答案: listanswers =db.tblanswers.where(p=&gt; p.ExamQuestionId exists in listquestionold?

【问题讨论】:

标签: c# linq entity-framework lambda


【解决方案1】:

使用ListContains 方法很容易:

var listquestionold = db.tblExamQuetions.Where(p => p.QuetionExamId == oldexamid).ToList();
var listanswers = db.tblanswers.Where(w => listquestionold.Contains(w.ExamQuestionId)).ToList();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多