0

LINQ で WHERE 句を作成する際に問題があります。私はそれをグーグルで検索しようとしましたが、外部変数がnull可能な整数のタイプである場合にどうするかについての答えしか得られませんでした...まあ、私はこれらの方法を逆に試しました(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 に答える