首页 > 解决方案 > 为什么我得到这个错误序列不包含元素

问题描述

我在视图中使用以下代码并尝试了很多解决方案,但仍然收到此错误 Sequence Contains no elements ,这是视图代码:

    @model AljawdahNewSite.Models.Orders_Tables
    @{
        ViewBag.Title = "Result Details";
        //Layout = "~/Views/Shared/_LayoutPatients.cshtml";
        var hema = new List<int>() { 1 };
        var bio = new List<int>() { 2 };
        var ser = new List<int>() { 3 };
        var hor = new List<int>() { 4 };
        var histo = new List<int>() { 5 };
        var culture = new List<int>() { 8 };
        var para = new List<int>() { 6 };
        var covid = new List<int>() { 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 => x.deptid == 1);
        var labBio = LabResults.FirstOrDefault(x => x.deptid == 2);
        var labSer = LabResults.FirstOrDefault(x => x.deptid == 3);
        var labHor = LabResults.FirstOrDefault(x => x.deptid == 4);
        var labcovid = LabResults.FirstOrDefault(x => 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 => x.DEPTID == 1);
        var labBio1 = LABCLINICVIEW.FirstOrDefault(x => x.DEPTID == 2);
        var labSer1 = LABCLINICVIEW.FirstOrDefault(x => x.DEPTID == 3);
        var labHor1 = LABCLINICVIEW.FirstOrDefault(x => x.DEPTID == 4);
        var labcovid1 = LABCLINICVIEW.FirstOrDefault(x => x.DEPTID == 9);
    } 


 
<div id="coviddiv">
        @if (labcovid1 != null && labcovid1.Report_Date.HasValue)
        {


            <table class="table table-bordered">
                <tr>
                    <td style="text-align:center">
                        <input type="submit" value="Covid-19 Result " @*onclick="PrintElemser('#serdiv')"*@ class="btn btn-primary" />
                        <a href="/RPT/WebForm1.aspx/?order_number=@Model.labClinicsViewResult.First().order_number&deptid=9&testid=@Model.labClinicsViewResult.First().Test_Id&Culture=@Model.labClinicsViewResult.First().Culture" class="btn btn-danger">Download Covid Result</a>
                    </td>
                </tr>
            </table>
            <div>
                <dl class="horizontal" style="border:solid;padding:10px">
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labClinicsViewResult.FirstOrDefault().Patient_Name)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labClinicsViewResult.FirstOrDefault().Patient_Name)</dd>
                    <dt style="width: 22%;display: inline-block;color:blue;margin-left:-20px">@Html.DisplayNameFor(model => model.labClinicsViewResult.FirstOrDefault().Customer_Name)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labClinicsViewResult.FirstOrDefault().Customer_Name)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labClinicsViewResult.FirstOrDefault().Patient_No)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labClinicsViewResult.FirstOrDefault().Patient_No)</dd>
                    <dt style="width: 22%;display: inline-block;margin-left:0px;color:blue;margin-left:-20px">@Html.DisplayNameFor(model => model.labClinicsViewResult.FirstOrDefault().Collection_Date)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labClinicsViewResult.FirstOrDefault().Collection_Date)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labClinicsViewResult.FirstOrDefault().SEX)</dt>
                    <dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labClinicsViewResult.FirstOrDefault().SEX)</dd>
                    <dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.labClinicsViewResult.FirstOrDefault().Receiving_Date)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labClinicsViewResult.FirstOrDefault().Receiving_Date)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labClinicsViewResult.FirstOrDefault().AGE)</dt>
                    <dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labClinicsViewResult.FirstOrDefault().AGE)</dd>
                    <dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.labClinicsViewResult.FirstOrDefault().Report_Date)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.labClinicsViewResult.FirstOrDefault().Report_Date)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.labClinicsViewResult.FirstOrDefault().order_number)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.labClinicsViewResult.FirstOrDefault().order_number)</dd>
                </dl>
            </div>
            <div class="tab-pane container active" id="home">
                <h5 class="text-uppercase p-2 text-center">Molecular Unit</h5>
                <table class="table table-bordered" cellpadding="5" cellspacing="5" border="1">
                    <thead>
                        <tr>
                            @*<th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Patient_No)</th>
                                <th>@Html.DisplayNameFor(m => m.labCashView.FirstOrDefault().Patient_Name)</th>*@
                            <th>@Html.DisplayNameFor(m => m.labClinicsViewResult.FirstOrDefault().Test_Name)</th>
                            <th>@Html.DisplayNameFor(m => m.labClinicsViewResult.FirstOrDefault().Result)</th>
                            <th>@Html.DisplayNameFor(m => m.labClinicsViewResult.FirstOrDefault().Low_Range)</th>
                            <th>@Html.DisplayNameFor(m => m.labClinicsViewResult.FirstOrDefault().High_Range)</th>
                            <th>@Html.DisplayNameFor(m => m.labClinicsViewResult.FirstOrDefault().Text_Range)</th>
                            <th>@Html.DisplayNameFor(m => m.labClinicsViewResult.FirstOrDefault().Report_Date)</th>

                        </tr>
                    </thead>
                    @foreach (var employee in Model.labClinicsViewResult.Where(x => covid.Contains(x.DEPTID.GetValueOrDefault())))
                {
                        <tr>
                            @*<td>@employee.Patient_No</td>
                                <td>@employee.Patient_Name</td>*@
                            <td>@employee.Test_Name</td>
                            <td>@employee.Result</td>
                            <td>@employee.Low_Range</td>
                            <td>@employee.High_Range</td>
                            <td>@employee.Text_Range</td>
                            <td>@employee.Report_Date</td>

                        </tr>
                    }
                </table>
            </div>

        }

    </div>

<div id="paradiv">
        @if (labPara1 != null && labPara1.Report_Date.HasValue)
        {
          
            
            <table class="table table-bordered">
                <tr>
                    <td style="text-align:center">
                        <h3>  <input type="submit" style="text-align:center" value="Parasitology Result " onclick="PrintElempar('#paradiv')" class="btn btn-primary" /></h3>
                        <a href="/RPT/WebForm1.aspx/?order_number=@Model.LabParaResult.First().ORDER_ID&deptid=@Model.LabParaResult.First().deptid&testid=@Model.LabParaResult.First().TESTID&Culture=2" class="btn btn-danger">Print Parasitology Result</a>
                    </td>
                </tr>
            </table>
            <div>
                <dl class="horizontal" style="border:solid;padding:10px">
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.LabParasitologyView.FirstOrDefault().Patient_Name)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.LabParasitologyView.FirstOrDefault().Patient_Name)</dd>
                    <dt style="width: 22%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.LabParasitologyView.FirstOrDefault().Customer_Name)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.LabParasitologyView.FirstOrDefault().Customer_Name)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.LabParasitologyView.FirstOrDefault().Patient_No)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.LabParasitologyView.FirstOrDefault().Patient_No)</dd>
                    <dt style="width: 22%;display: inline-block;margin-left:0px;color:blue;">@Html.DisplayNameFor(model => model.LabParasitologyView.FirstOrDefault().Collection_Date)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.LabParasitologyView.FirstOrDefault().Collection_Date)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.LabParasitologyView.FirstOrDefault().SEX)</dt>
                    <dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.LabParasitologyView.FirstOrDefault().SEX)</dd>
                    <dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.LabParasitologyView.FirstOrDefault().Receiving_Date)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.LabParasitologyView.FirstOrDefault().Receiving_Date)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.LabParasitologyView.FirstOrDefault().AGE)</dt>
                    <dd style="width: 20%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.LabParasitologyView.FirstOrDefault().AGE)</dd>
                    <dt style="width: 22%;display: inline-block;margin-left:60px;color:blue;">@Html.DisplayNameFor(model => model.LabParasitologyView.FirstOrDefault().Report_Date)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.LabParasitologyView.FirstOrDefault().Report_Date)</dd>
                    <dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.LabParasitologyView.FirstOrDefault().order_number)</dt>
                    <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:-50px">@Html.DisplayFor(model => model.LabParasitologyView.FirstOrDefault().order_number)</dd>
                    @*<dt style="width: 20%;display: inline-block;color:blue;">@Html.DisplayNameFor(model => model.LabParasitologyView.FirstOrDefault().Test_Name)</dt>
                        <dd style="width: 25%;display: inline-block;margin: 0px;margin-left:25px">@Html.DisplayFor(model => model.LabParasitologyView.FirstOrDefault().Test_Name)</dd>*@
                </dl>
            </div>
            <div class="tab-pane container active" id="home">
                @*<h5 class="text-uppercase p-2 text-center">Parasitology Department</h5>*@
                <div>
                    @*<dl class="horizontal" style="border:solid">
                            <dd style="width: 40%;display: inline-block;margin: 0px;margin-left:0px">@Html.DisplayFor(model => model.LabParasitologyView.FirstOrDefault().Test_Name)</dd>
                        </dl>*@


                    <table class="table table-bordered" cellpadding="5" cellspacing="5" border="1">
                        <thead>
                            <tr>
                                <th>@Html.DisplayNameFor(m => m.labtests.FirstOrDefault().TestName)</th>
                                <th>@Html.DisplayNameFor(m => m.LabParasitologyView.FirstOrDefault().SERIAL)</th>
                                <th>@Html.DisplayNameFor(m => m.LabParasitologyView.FirstOrDefault().TEXT)</th>
                                <th>@Html.DisplayNameFor(m => m.LabParasitologyView.FirstOrDefault().RESULT)</th>
                                <th>@Html.DisplayNameFor(m => m.LabParasitologyView.FirstOrDefault().UNIT)</th>
                                <th>@Html.DisplayNameFor(m => m.LabParasitologyView.FirstOrDefault().Reference_Range)</th>
                                <th>@Html.DisplayNameFor(m => m.LabParasitologyView.FirstOrDefault().Report_Date)</th>



                            </tr>
                        </thead>
                        @foreach (var employee in Model.LabParaResult.Where(x => para.Contains(x.deptid.GetValueOrDefault())))
                {
                            <tr>

                                <td>@employee.LabTests.TestName</td>
                                <td>@employee.SERIAL</td>
                                <td>@employee.TEXT</td>
                                <td>@employee.VALUE</td>
                                <td>@employee.unit</td>
                                <td>@employee.reference_range</td>
                                <td>@employee.APPROVED_DATE</td>



                            </tr>
                        }
                    </table>
                </div>
            </div>
        }
    </div>

这是控制器代码的一部分:

public ActionResult MasterDetails(int id)
        {

              
            var tables = new Orders_Tables
            {
                testsRanges = db.TestsRanges.ToList(),

                LabResults = db.LAB_RESULTS.Where(o => o.ORDER_ID == id)
                             .Include(p => p.LabTests)
                             .Include(t => t.Patients).ToList(),


                LabParaResult = db.LAB_PARA_RESULTS.Where(o => o.ORDER_ID == id).Include(t => t.Patients).Include(t => t.LabTests).Include(c => c.Customers).ToList(),
                LabCultureResults = db.LAB_CULTURE_RESULT.Where(o => o.ORDER_ID == id).Include(t => t.Patients).Include(t => t.LabTests).Include(c => c.Customers).ToList(),
                LabMicroResults = db.LAB_MICRO_NEGATIVE_RESULT.Where(o => o.ORDER_ID == id).ToList(),
                labCashView = db.LAB_RESULT_CASH_VIEW.Where(o => o.order_number == id).ToList(),
                labClinicsViewResult = db.LAB_RESULTS_CLINIC_VIEW.Where(o => o.order_number == id).ToList(),
                LabParasitologyView = db.LAB_PARASITOLOGY_VIEW.Where(o => o.order_number == id).ToList(),
                
            };

            return View(tables);
           
        }

尝试运行结果时显示错误

var labPara1 = Model.LabParasitologyView.FirstOrDefault(); 

但错误出现在这一行

var labcovid1 = LABCLINICVIEW.FirstOrDefault(x => x.DEPTID == 9);

在此处输入图像描述

我需要你的帮助:

我将如何处理控制器代码

如果labClinicsViewResult 为空且不返回值,则跳过并转到下一个?

这是课程:

public class Orders_Tables
{
   // internal IQueryable<object> result { get; set; }
    public Lab_Orders  LabOrders { get; set; }
    public Lab_orders_Cash LabOrdersCash { get; set; }
    public Lab_Sample_status LabOrderStatus { get; set; }

    public IEnumerable<LAB_RESULTS> LabResults { get; set; }

    public IEnumerable<TestsRanges> testsRanges { get; set; }

    public IEnumerable<TestsUnits>  testUnits { get; set; }

    public IEnumerable<LAB_CULTURE_RESULT> LabCultureResults { get; set; }

    public IEnumerable<LAB_MICRO_NEGATIVE_RESULT> LabMicroResults { get; set; }
    public IEnumerable<LabTests> labtests { get; set; }
    public IEnumerable<LAB_RESULTS_CLINIC_VIEW> labClinicsViewResult { get; set; }
    public IEnumerable<LAB_RESULT_CASH_VIEW> labCashView { get; set; }

    public IEnumerable<LAB_PARASITOLOGY_VIEW> LabParasitologyView { get; set; }

    public IEnumerable<LAB_CULTURES_VIEW> LabCulturesView { get; set; }

    public IEnumerable<LAB_MICRO_VIEW> LabMicroView { get; set; }

    public IEnumerable<LAB_HISTOPATHOLOGY_VIEW> LabHistopathologyView { get; set; }

    public IEnumerable<LAB_HISTO_RESULT> LabHistoResult { get; set; }

    public IEnumerable<LAB_PARA_RESULTS> LabParaResult { get; set; }

    public Lab_Hematology_Samples LabSamples { get; set; }

  public Patients patients { get; set; }

    public IEnumerable<Customers> customers { get; set; }
}

这是类定义:

public partial class LAB_RESULTS_CLINIC_VIEW
    {
        public int order_number { get; set; }
        public int Test_Id { get; set; }
        public string Test_Name { get; set; }
        public Nullable<int> Result_Duration { get; set; }
        public Nullable<int> Culture { get; set; }
        public string Normal { get; set; }
        public Nullable<System.DateTime> Report_Date { get; set; }
        public string Result { get; set; }
        public string Notes { get; set; }
        public string Low_Range { get; set; }
        public string High_Range { get; set; }
        public string Panic { get; set; }
        public string Text_Range { get; set; }
        public string machine_name { get; set; }
        public Nullable<int> Customer_No { get; set; }
        public string Customer_Name { get; set; }
        public Nullable<int> Patient_No { get; set; }
        public string Patient_Name { get; set; }
        public string Clinic_File_No { get; set; }
        public string Category { get; set; }
        public Nullable<int> AGE { get; set; }
        public string SEX { get; set; }
        public string Test_Note { get; set; }
        public string UNIT { get; set; }
        public Nullable<int> DEPTID { get; set; }
        public Nullable<System.DateTime> Collection_Date { get; set; }
        public Nullable<System.DateTime> Receiving_Date { get; set; }
        public string Group_Name { get; set; }
        public Nullable<int> SERIAL { get; set; }
        public int GROUPID { get; set; }
        public Nullable<int> packageid { get; set; }
        public string EXAMINED_BY { get; set; }
        public string APPROVED_BY { get; set; }
        public string UPDATED_BY { get; set; }
        public Nullable<System.DateTime> UPDATED_DATE { get; set; }
        public string Comments { get; set; }
        public string department_name { get; set; }
    }

这是数据库中的视图脚本:

CREATE VIEW [dbo].[LAB_RESULTS_CLINIC_VIEW] AS 

SELECT  DISTINCT [LAB_RESULTS].ORDER_ID  as 'order number'
       ,labtests.TestId as 'Test Id'   
       ,labtests.TestName as 'Test Name'
       ,labtests.test_duration as 'Result Duration'
       ,labtests.culture as 'Culture'
       ,NORMAL_RESULT as 'Normal'     
       ,cast(LAB_RESULTS.APPROVED_DATE as datetime) as 'Report Date'
       ,CASE WHEN coalesce([RESULT_NUMBER],'') <> '' THEN RESULT_NUMBER WHEN coalesce(RESULT_REPORT, '') <> '' THEN RESULT_REPORT END AS Result 
       ,[RESULT_NOTE]   as 'Notes'
     ,TestsRanges.LowerLimit as 'Low Range'
      ,TestsRanges.UpperLimit as 'High Range'
     ,TestsRanges.panic_value as 'Panic'
      ,TestsRanges.text_range as 'Text Range'
       ,machines.machine_name
      ,LAB_RESULTS.CUSTID as 'Customer No'
      ,Customers.CustName as 'Customer Name'
      ,LAB_RESULTS.patient_no as 'Patient No'
      ,Patients.PATIENT_NAME as 'Patient Name'
      ,Patients.PCfileNo as 'Clinic File No'
      ,patientcat.CatName as 'Category'
      ,Patients.Age AS 'AGE'
      ,gender.gendername as 'SEX'
      ,labtests.TestNotes as 'Test Note'
      ,TestsUnits.UnitName as 'UNIT'
      ,LAB_RESULTS.deptid AS 'DEPTID'
      ,cast(Lab_Hematology_Samples.COLLECTION_DATE as datetime) as 'Collection Date'
      ,cast(Lab_Hematology_Samples.RECEIVING_DATE as datetime) as 'Receiving Date'
      ,Groups.groupdesc as 'Group Name'
      ,LAB_RESULTS.SERIAL
      ,LAB_RESULTS.GROUPID
      ,LAB_RESULTS.packageid
      ,LAB_RESULTS.EXAMINED_BY
      ,LAB_RESULTS.APPROVED_BY
      ,UPDATED_BY
      ,UPDATED_DATE
      ,Lab_Result_Comments.comments as 'Comments'
      ,Departments.Dept_name as 'department name'
      ,[LAB_RESULTS].branch_id as 'branchid'
     
      
  FROM [dbo].[LAB_RESULTS]
  inner join LabTests on LabTests.testid=LAB_RESULTS.TESTID
  inner join TestsRanges on  LAB_RESULTS.TESTID=TestsRanges.TestId 
  inner join Departments on  LAB_RESULTS.deptid=Departments.Dept_id 
  inner join PatientCat on patientcat.CatId = TestsRanges.CatId
  inner join Customers on Customers.CustId=LAB_RESULTS.CUSTID
  inner join patients on Patients.Patient_No = LAB_RESULTS.patient_no
 inner join machines on lab_results.machine_id = machines.machine_id
  inner join gender on gender.genderid = Patients.Gender
  inner join TestsUnits on TestsUnits.UnitId = LabTests.UnitId
  inner join Lab_Orders on Lab_Orders.ORDER_ID = LAB_RESULTS.ORDER_ID
  left join Lab_Result_Comments on LAB_RESULTS.ORDER_ID = Lab_Result_Comments.ORDER_ID
  inner join Lab_Hematology_Samples on Lab_Hematology_Samples.SAMPLE_ID = LAB_RESULTS.SAMPLE_ID
  inner join Groups on (Groups.groupid = LAB_RESULTS.GROUPID and Groups.Testid = LAB_RESULTS.TESTID )

  where (Lab_Orders.catid = TestsRanges.CatId or PatientCat.CatId =5)
  and  LAB_RESULTS.EXAMINED_DATE is not null 
  and  LAB_RESULTS.APPROVED_DATE is not null
  and  LAB_RESULTS.SAMPLE_STATUS=6
 and  (Patients.Gender = TestsRanges.PatientSex or TestsRanges.PatientSex = 1 )
  AND TestsRanges.machine_id = LAB_RESULTS.machine_id
 -- and LAB_RESULTS.update_count in (select max(update_count) from LAB_RESULTS where SAMPLE_STATUS = 6 and deptid = @deptid and ORDER_ID = @ORDER_ID)
 AND LAB_RESULTS.DEPTID IN (1,2,3,4,9)
  
  UNION ALL 
 
 SELECT DISTINCT [LAB_RESULTS].ORDER_ID  as 'order number'
       ,labtests.TestId as 'Test Id'     
       ,labtests.TestName as 'Test Name'
       ,labtests.test_duration as 'Result Duration'
       ,labtests.culture as 'Culture'
       ,NORMAL_RESULT as 'Normal'     
       ,cast(APPROVED_DATE as datetime) as 'Report Date'
       ,CASE WHEN coalesce([RESULT_NUMBER],'') <> '' THEN RESULT_NUMBER WHEN coalesce(RESULT_REPORT, '') <> '' THEN RESULT_REPORT END AS Result 
       ,[RESULT_NOTE]   as 'Notes'
      ,TestsRanges.LowerLimit as 'Low Range'
      ,TestsRanges.UpperLimit as 'High Range'
      ,TestsRanges.panic_value as 'Panic'
      ,TestsRanges.text_range as 'Text Range'
       ,machines.machine_name
      ,LAB_RESULTS.CUSTID as 'Customer No'
      ,Customers.CustName as 'Customer Name'
      ,LAB_RESULTS.patient_no as 'Patient No'
      ,Patients.PATIENT_NAME as 'Patient Name'
      ,Patients.PCfileNo as 'Clinic File No'
      ,patientcat.CatName as 'Category'
      ,Patients.Age AS 'AGE'
      ,gender.gendername as 'SEX'
      ,labtests.TestNotes as 'Test Note'
      ,TestsUnits.UnitName as 'UNIT'
      ,LAB_RESULTS.deptid AS 'DEPTID'
      ,cast(Lab_Hematology_Samples.COLLECTION_DATE as datetime) as 'Collection Date'
      ,cast(Lab_Hematology_Samples.RECEIVING_DATE as datetime)as 'Receiving Date'
      ,NULL AS 'Group Name'
      ,LAB_RESULTS.SERIAL
      ,LAB_RESULTS.GROUPID
      ,LAB_RESULTS.packageid
      ,LAB_RESULTS.EXAMINED_BY
      ,LAB_RESULTS.APPROVED_BY
      ,UPDATED_BY
      ,UPDATED_DATE
      ,Lab_Result_Comments.comments as 'Comments'
      ,Departments.Dept_name as 'department name'
      ,[LAB_RESULTS].branch_id as 'branchid'
      
      
  FROM [dbo].[LAB_RESULTS]
  inner join LabTests on LabTests.testid=LAB_RESULTS.TESTID
   inner join TestsRanges on TestsRanges.TestId = LAB_RESULTS.TESTID
   inner join Departments on  LAB_RESULTS.deptid=Departments.Dept_id 
  inner join PatientCat on patientcat.CatId = TestsRanges.CatId
  inner join Customers on Customers.CustId=LAB_RESULTS.CUSTID
  inner join machines on lab_results.machine_id = machines.machine_id
  inner join patients on Patients.Patient_No = LAB_RESULTS.patient_no
  inner join gender on gender.genderid = Patients.Gender
  inner join TestsUnits on TestsUnits.UnitId = LabTests.UnitId
  left join Lab_Result_Comments on LAB_RESULTS.ORDER_ID = Lab_Result_Comments.ORDER_ID
  inner join Lab_Orders on Lab_Orders.ORDER_ID = LAB_RESULTS.ORDER_ID
  inner join Lab_Hematology_Samples on Lab_Hematology_Samples.SAMPLE_ID = LAB_RESULTS.SAMPLE_ID
  

  where (Lab_Orders.catid = TestsRanges.CatId or PatientCat.CatId =5)
  and  LAB_RESULTS.EXAMINED_DATE is not null 
  and  LAB_RESULTS.APPROVED_DATE is not null
  and  LAB_RESULTS.SAMPLE_STATUS=6
  and  (Patients.Gender = TestsRanges.PatientSex or TestsRanges.PatientSex = 1 )
  and  LAB_RESULTS.GROUPID = 0
 -- and LAB_RESULTS.update_count in (select max(update_count) from LAB_RESULTS where SAMPLE_STATUS = 6 and deptid = @deptid and ORDER_ID = @ORDER_ID)
 -- and LAB_RESULTS.deptid = @deptid
  AND TestsRanges.machine_id = LAB_RESULTS.machine_id
  AND LAB_RESULTS.DEPTID IN (1,2,3,4,9)

解释有关该问题的更多详细信息:

医生登录网站并通过单击结果按钮打开结果,

如果部门 (1,2,3,4,5,9) 中的结果,控制器 masterdetails 将在下一页显示结果

但是如果部门(6,8)中的结果属于表(LAB_PARA_RESULTS 或 LAB_CULTURE_RESULT)

它没有打开并显示错误这是错误之前的图像:

在此处输入图像描述

标签: c#asp.net-mvc

解决方案


看起来不包含任何元素的序列是LABCLINICVIEW. 这是从您的模型变量分配的Orders_Tables.labClinicsViewResult。您正在使用数据库调用分配此变量db.LAB_RESULTS_CLINIC_VIEW.Where(o => o.order_number == id).ToList(),因此在我看来,此数据库调用返回一个空集。尝试调试并单步执行并停止该行return View(tables);,然后检查您的变量tables以查看该成员变量tables.labClinicsViewResult实际上是否包含任何内容。如果它是空的,那是你的问题。如果它不为空,那么您的问题可能出在调用中var labcovid1 = LABCLINICVIEW.FirstOrDefault(x => x.DEPTID == 9);,并且它可能没有DEPTID等于的值9


推荐阅读