특정 퀴즈에 포함되지 않은 질문 표에서 모든 질문을 선택하고 싶습니다. 제 질문은 아래의 코드가 메시지와 함께 실패하는 이유입니다.linq sql 오류 : 텍스트 데이터 형식을 비교할 수 없기 때문에 별개로 선택할 수 없습니다.
텍스트 데이터 유형은 비교할 수 없으므로 DISTINCT로 선택할 수 없습니다. 데이터 유형 text 및 text는 is 연산자에서 호환되지 않습니다. 이 잘 작동으로
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);
}
}
}
감사합니다. Jon, 그 작품. 다른 테이블에 대해 잘 작동하는 비슷한 쿼리가 있습니다. 나는이 경우 문제가 questiontext 필드의 데이터 유형과 관련이 있다고 생각한다. 이것은 'text'유형이다. – krishna
나중에 내 가정을 테스트 할 것입니다. 다시 감사드립니다. – krishna
실제로, 생성 된 SQL을 살펴볼 가치가 있습니다. 나는 당신의 다른 질문이 왜 효과가 있는지 설명 할 것입니다. 솔직히 말하면, 텍스트 컬럼에서 작동하도록 스키마를 변경할 수있는 방법이있을 수 있습니다. –