0

我在使用 LINQ 制作 WHERE 子句时遇到问题。我试图用谷歌搜索它,但如果外部变量是可空整数的类型,我只能得到答案......好吧,我已经反过来尝试了这些方法(我有 0...1 关系在我的数据集中):例如

int oldId = oldQuestion.id;
IEnumerable<possible_answer> possibleAnswersQuery =
            from x in Mentor11Entities.possible_answers
            where object.Equals(x.question_id, oldId)
            select x;
List<possible_answer> possibleAnswers = 
            possibleAnswersQuery.ToList<possible_answer>();

或者

int oldId = oldQuestion.id;
IEnumerable<possible_answer> possibleAnswersQuery =
            from x in Mentor11Entities.possible_answers
            where Convert.ToInt32(x.question_id ?? 0).Equals(oldId)
            select x;
List<possible_answer> possibleAnswers = 
            possibleAnswersQuery.ToList<possible_answer>();

但我总是收到LINQ不支持某些功能的错误......有什么办法可以解决这个问题吗?

4

1 回答 1

4

只需使用

where x.question_id != null && x.question_id == oldId

所以你的查询应该是:

IEnumerable<possible_answer> possibleAnswersQuery =
            from x in Mentor11Entities.possible_answers
            where x.question_id != null && x.question_id == oldId
            select x;
于 2012-07-18T04:54:19.017 回答