title: why I got error Sequence contains no elements in some tables
body: <p>I am using LINQ and all orders date appear and show only parasitology not appear and
  show error when I try to open the order details sequence contain no elements
  why I got this error , I checked the stackoverflow questions and answers but cannot find the exact reason</p>
  <p>this is the controller code:</p>
  <pre><code>public ActionResult MasterDetails(int id)
          {
  
              var result = (from labResult in db.LAB_RESULTS
                            join labTest in db.LabTests on labResult.TESTID equals labTest.TestId
                            join testRange in db.TestsRanges on labResult.TESTID equals testRange.TestId
                            where labResult.ORDER_ID == id
                            select new { labResult.ORDER_ID, labResult.patient_no, labTest.TestId, labTest.TestName, testRange.LowerLimit, testRange.UpperLimit }).Distinct();
  
  
              var tables = new Orders_Tables
              {
                  testsRanges = db.TestsRanges.ToList(),
                  labtests = db.LabTests.ToList(),
                  LabResults = db.LAB_RESULTS.Where(o =&gt; o.ORDER_ID == id).ToList(),
  
  
                  LabParaResult = db.LAB_PARA_RESULTS.Where(o =&gt; o.ORDER_ID == id).ToList(),
                  LabCultureResults = db.LAB_CULTURE_RESULT.Where(o =&gt; o.ORDER_ID == id).ToList(),
                  LabMicroResults = db.LAB_MICRO_NEGATIVE_RESULT.Where(o =&gt; o.ORDER_ID == id).ToList(),
                  labCashView = db.LAB_RESULT_CASH_VIEW.Where(o =&gt; o.order_number == id).ToList(),
                  labClinicsViewResult = db.LAB_RESULTS_CLINIC_VIEW.Where(o =&gt; o.order_number == id).ToList(),
                  LabParasitologyView = db.LAB_PARASITOLOGY_VIEW.Where(o =&gt; o.order_number == id).ToList(),
                  LabCulturesView = db.LAB_CULTURES_VIEW.Where(o =&gt; o.ORDER_ID == id).ToList(),
                  LabMicroView = db.LAB_MICRO_VIEW.Where(o =&gt; o.ORDER_ID == id).ToList(),
                  LabHistopathologyView = db.LAB_HISTOPATHOLOGY_VIEW.Where(o =&gt; o.ORDER_ID == id).ToList(),
                  LabHistoResult = db.LAB_HISTO_RESULT.Where(o =&gt; o.ORDER_ID == id).ToList(),
                 // LABINVOICEVIEW = db.LAB_INVOICE_VIEW.Where(inv=&gt; inv.order_id == id).ToList(),
                  
                 // patients = db.Patients.ToList()
              };
  
              return View(tables);
             
          }
  </code></pre>
  <p>this is view code :</p>
  <pre><code>@model AljawdahNewSite.Models.Orders_Tables
  @{
      ViewBag.Title = &quot;Result Details&quot;;
      //Layout = &quot;~/Views/Shared/_LayoutPatients.cshtml&quot;;
      var hema = new List&lt;int&gt;() { 1 };
      var bio = new List&lt;int&gt;() { 2 };
      var ser = new List&lt;int&gt;() { 3 };
      var hor = new List&lt;int&gt;() { 4 };
      var histo = new List&lt;int&gt;() { 5 };
      var culture = new List&lt;int&gt;() { 8 };
      var para = new List&lt;int&gt;() { 6,10 };
      var covid = new List&lt;int&gt;() { 9 };
  
      var labPara = Model.LabParaResult.FirstOrDefault();
      var labCult = Model.LabCultureResults.FirstOrDefault();
      var labMicro = Model.LabMicroResults.FirstOrDefault();
      var labHisto = Model.LabHistoResult.FirstOrDefault();
      var LabResults = Model.LabResults;
      var labhema = LabResults.FirstOrDefault(x =&gt; x.deptid == 1);
      var labBio = LabResults.FirstOrDefault(x =&gt; x.deptid == 2);
      var labSer = LabResults.FirstOrDefault(x =&gt; x.deptid == 3);
      var labHor = LabResults.FirstOrDefault(x =&gt; x.deptid == 4);
      var labcovid = LabResults.FirstOrDefault(x =&gt; x.deptid == 9);
  
      var LABCLINICVIEW = Model.labClinicsViewResult;
      var LABCASHVIEW = Model.labCashView;
      var labPara1 = Model.LabParasitologyView.FirstOrDefault();
      var labCult1 = Model.LabCulturesView.FirstOrDefault();
      var labMicro1 = Model.LabMicroView.FirstOrDefault();
      var labHisto1 = Model.LabHistopathologyView.FirstOrDefault();
      var labhema1 = LABCLINICVIEW.FirstOrDefault(x =&gt; x.DEPTID == 1);
      var labBio1 = LABCLINICVIEW.FirstOrDefault(x =&gt; x.DEPTID == 2);
      var labSer1 = LABCLINICVIEW.FirstOrDefault(x =&gt; x.DEPTID == 3);
      var labHor1 = LABCLINICVIEW.FirstOrDefault(x =&gt; x.DEPTID == 4);
      var labcovid1 = LABCLINICVIEW.FirstOrDefault(x =&gt; x.DEPTID == 9);
  } 
  </code></pre>
  <p>the error in the screen shot :</p>
  <p><a href="https://i.stack.imgur.com/W41jA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W41jA.png" alt="enter image description here" /></a></p>
  <p>I can view all orders only this order in this table show this error :</p>
  <pre><code>var labPara1 = Model.LabParasitologyView.FirstOrDefault(); in view 
  LabParaResult = db.LAB_PARA_RESULTS.Where(o =&gt; o.ORDER_ID == id).ToList(),  in controller 
  </code></pre>
  <p>how to solve this error please I need help ?</p>