0

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

3
  • Could you not do something like. select from table a where a.id not in (select id from table b). Is this not like something you want? stackoverflow.com/questions/21766856/… Commented May 26, 2020 at 13:47
  • I'm not seeing any SQL here... It should be simple enough to do though, something like this ought to do it: select * from tbl1 a where a.id not in (select distinct(b.id) from tbl2 b) Commented May 26, 2020 at 13:58
  • yes i try something like this var subselect = (from b in BlackList select b.CusId).ToList(); var result = from c in Customer where !subselect.Contains(c.CusId) select c; but not working will it loop in list of items Commented May 26, 2020 at 14:11

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.