I am getting a NullReferenceException
when trying to run the following query:
var questions = db.questions
.Where(t => Ids.Contains(t.id));
foreach (var q in questions) // exception
{
var a = q.id;
}
The exception rises in the foreach statement.
In the database I have a questions
table with one record with an Id = 1.
If I query with t => t.id == 1
I get results.
The Ids is a List<long>
type. When running the code, the Ids variable contains one item, which is the value 1.
My goal is to retrieve the questions with id (primary key) that equals to one or more Ids in the Ids
list.
So for example: if the list contains the numebrs 1,3,5, the query should return the rows from the questions table that match records with the corresponding Ids,which are 1,3 and 5.
Using Entity Framework 6 with MySQL.