【发布时间】:2009-08-20 13:31:58
【问题描述】:
我想从问题表中选择尚未包含在特定测验中的所有问题。 我的问题是为什么下面的代码会失败并显示消息:
文本数据类型不能选择为 DISTINCT,因为它不可比较。 is 运算符中的数据类型 text 和 text 不兼容。
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);
在哪里可以正常工作:
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);
}
}
}
【问题讨论】:
标签: linq