I want to select all questions from the questions table that haven't been included already for a particular quiz. My question is why does the below code fail with the message :
The text data type cannot be selected as DISTINCT because it is not comparable. The data types text and text are incompatible in the is operator.
var allQuestions = from q in my.Questions
select new
{
Select = new Boolean(),
Id = q.QuestionId,
QuestionName = q.Name,
QuestionText = q.Text,
Topic = q.Topic.Title
};
var currentQuestions = from cq in my.QuizQuestions
where cq.Quiz.quizId == quizId
select new
{
Select = new Boolean(),
Id = cq.Questions.QuestionId,
QuestionName = cq.Questions.Name,
QuestionText = cq.Questions.Text,
Topic = cq.Questions.Topic.Title
};
var selectQuestions = allQuestions.Except(currentQuestions);
Where as this works fine:
var allQuestions = (from q in my.Questions
select new
{
Select = new Boolean(),
Id = q.QuestionId,
QuestionName = q.Name,
QuestionText = q.Text,
Topic = q.Topic.Title
}).ToList();
var currentQuestions = (from cq in my.QuizQuestions
where cq.Quiz.quizId == quizId
select new
{
Select = new Boolean(),
Id = cq.Questions.QuestionId,
QuestionName = cq.Questions.Name,
QuestionText = cq.Questions.Text,
Topic = cq.Questions.Topic.Title
}).ToList();
int allquestionsCount = allQuestions.Count();
for (int i = allquestionsCount; i < 0; i--)
{
foreach(var question in currentQuestions){
if (question.Id.Equals(allQuestions.ElementAt(i - 1).Id))
{
allQuestions.RemoveAt(i - 1);
}
}
}