I have a table that I need to select a number of unique rows, but I want to exclude the rows with the same id which are saved in another table.
My first attempt is to select rows which saved before
var QuestionsAnswered = await _context.answers
.Where(e => e.Userid == Userid)
.Select(a => new
{
Qid = a.Questionid
}) .ToListAsync();
My return is
return View(await _context.questions
.OrderBy(x => Guid.NewGuid())
.Take(10)
.ToListAsync());
what i have done is
var QuestionsAnswered = await _context.answers
.Where(e => e.Userid == Userid)
.Select(a => new
{
Qid = a.Questionid
}) .ToListAsync();
var AllQuestions = await _context.questions.ToListAsync();
foreach (var qid in AllQuestions)
{
int QuestionValueId = qid.QuestionId;
foreach (var item in QuestionsAnswered)
{
if (item.Qid == QuestionValueId)
{
AllQuestions.RemoveAll(a => a.QuestionId == QuestionValueId);
}
}
but no sense