指定的包含路径无效.EntityType 'DB_A50B96_aljawdahlabModel.LAB_RESULTS' [英] A specified Include path is not valid. The EntityType 'DB_A50B96_aljawdahlabModel.LAB_RESULTS'

查看:70
本文介绍了指定的包含路径无效.EntityType 'DB_A50B96_aljawdahlabModel.LAB_RESULTS'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击详细信息链接时出现此错误,我想使用 .Include() 在表之间建立关系并读取患者姓名和测试名称,并且表和外键之间存在关系错误:

<块引用>

指定的包含路径无效.实体类型‘DB_A50B96_aljawdahlabModel.LAB_RESULTS’未声明名为‘patient_no’的导航属性."

这是 LAB_RESULTS 模型:

使用系统;使用 System.Collections.Generic;使用 System.ComponentModel.DataAnnotations.Schema;公共部分类 LAB_RESULTS{公共 int ID { 获取;放;}公共 int SAMPLE_ID { 获取;放;}公共 int ORDER_ID { 获取;放;}公共 int TESTID { 获取;放;}公共 int GROUPID { 获取;放;}公共字符串 NORMAL_RESULT { 获取;放;}公共 int SAMPLE_STATUS { 获取;放;}公共字符串 EXAMINED_BY { 获取;放;}public NullableEXAMINED_DATE { 获取;放;}公共字符串 APPROVED_BY { 获取;放;}public NullableAPPROVED_DATE { 获取;放;}公共字符串RESULT_NUMBER { 获取;放;}公共字符串 RESULT_REPORT { 获取;放;}公共字符串 RESULT_NOTE { 获取;放;}public Nullable包 ID { 获取;放;}public Nullablemachine_id { 获取;放;}public Nullable深度{得到;放;}[外键(患者号")]public Nullable病人_没有{得到;放;}public Nullablecustid { 得到;放;}公共字符串 REQ_FORM_NO { 获取;放;}public Nullable串行{得到;放;}公共字符串文本 { 获取;放;}公共字符串值 { 获取;放;}公共字符串包名 { 获取;放;}公共字符串 UPDATED_BY { 获取;放;}public NullableUPDATED_DATE { 获取;放;}public Nullableprio_id { 获取;放;}public Nullable更新计数{得到;放;}公共字符串 REJECTED_BY { 获取;放;}public NullableREJECTED_DATE { 得到;放;}public NullableREJECTED_REASON { 得到;放;}//public int Patient_no { get;放;}//公共患者患者 { get;放;}//公共 LabTests labtests { get;放;}公共虚拟 LabTests LabTests { 得到;放;}公共虚拟病人病人{得到;放;}}}

这是病人课:

使用系统;使用 System.Collections.Generic;公共部分类患者{[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]公共病人(){this.LAB_PARA_RESULTS = new HashSet();this.LAB_RESULTS = new HashSet();}公共 int Patient_No { 得到;放;}公共字符串 Patient_Name { 获取;放;}public Nullable年龄{得到;放;}公共字符串移动{获取;放;}公共字符串电子邮件{获取;放;}公共字符串地址{获取;放;}public Nullable性别{得到;放;}公共字符串 Patient_id { 获取;放;}public NullableNatid { 得到;放;}公共字节[] insurance_card { 得到;放;}公共字节[] ID_card { 获取;放;}公共字符串patient_Name_Arabic { 获取;放;}public Nullablecatid { 得到;放;}public Nullable出生日期{得到;放;}public Nullable日期添加 { 获取;放;}公共字符串AddedBy { get;放;}公共字符串 HijriBirthDate { get;放;}公共字符串 PCfileNo { 获取;放;}公共字符串 GregBirthDate { 获取;放;}[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]公共虚拟 ICollectionLAB_PARA_RESULTS { 得到;放;}[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]公共虚拟 ICollectionLAB_RESULTS { 得到;放;}}}

这是控制器:

public ActionResult CashData(int id){var 表 = 新 Orders_Tables{实验室结果 = db.LAB_RESULTS.include(p=>p.patient_no).Include(t=>t.TESTID).Where(o => o.ORDER_ID == id).ToList(),labtests = db.LabTests.ToList(),患者 = db.Patients.ToList()};返回视图(表格);}

这是视图:

@model AljawdahNewSite.Models.Orders_Tables@{ViewBag.Title = "现金数据";布局 = "~/Views/Shared/_LayoutPatients.cshtml";}<h2>现金数据</h2><ul class="nav nav-tabs"><li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#home">实验室结果</a><li class="nav-item"><a class="nav-link" data-toggle="tab" href="#menu1">部门</a><li class="nav-item"><a class="nav-link" data-toggle="tab" href="#menu2">奖励</a><div class="tab-content"><div class="tab-pane container active" id="home"><h3 class="text-center text-uppercase">员工列表</h3><table class="table table-bordered"><头><tr>@Html.DisplayNameFor(m => m.LabResults.FirstOrDefault().patient_no)@Html.DisplayNameFor(m => m.LabResults.FirstOrDefault().NORMAL_RESULT)@Html.DisplayNameFor(m => m.LabResults.FirstOrDefault().APPROVED_DATE)@Html.DisplayNameFor(m => m.patients.FirstOrDefault().Patient_Name)@Html.DisplayNameFor(m => m.labtests.FirstOrDefault().TestName)</tr></thead>@foreach(Model.LabResults 中的 var 员工){<tr><td>@employee.patient_no</td><td>@employee.NORMAL_RESULT</td><td>@employee.APPROVED_DATE</td><td>@employee.Patients.Patient_Name</td><td>@employee.LabTests.TestName</td></tr>}

我检查了解决方案,但情况不同,我检查了这个链接:

A指定的包含路径无效.EntityType 未声明名称为 *

的导航属性

出现在控制器中的错误如何解决?

解决方案

就像评论中提到的,你不能包含属性,只能实体,结果将是喜欢:

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

包括文档

I got this error when click details link , I want to make relation between tables by using .Include() and read the name of patient and test name and there is relation between the tables and Foreign Key The error :

"A specified Include path is not valid. The EntityType 'DB_A50B96_aljawdahlabModel.LAB_RESULTS' does not declare a navigation property with the name 'patient_no'."

This is LAB_RESULTS Model :

using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations.Schema;

        public partial class LAB_RESULTS
        {
            public int ID { get; set; }
            public int SAMPLE_ID { get; set; }
            public int ORDER_ID { get; set; }
            public int TESTID { get; set; }
            public int GROUPID { get; set; }
            public string NORMAL_RESULT { get; set; }
            public int SAMPLE_STATUS { get; set; }
            public string EXAMINED_BY { get; set; }
            public Nullable<System.DateTime> EXAMINED_DATE { get; set; }
            public string APPROVED_BY { get; set; }
            public Nullable<System.DateTime> APPROVED_DATE { get; set; }
            public string RESULT_NUMBER { get; set; }
            public string RESULT_REPORT { get; set; }
            public string RESULT_NOTE { get; set; }
            public Nullable<int> packageid { get; set; }
            public Nullable<int> machine_id { get; set; }
            public Nullable<int> deptid { get; set; }

            [ForeignKey("patient_no")]
            public Nullable<int> patient_no { get; set; }
            public Nullable<int> custid { get; set; }
            public string REQ_FORM_NO { get; set; }
            public Nullable<int> serial { get; set; }
            public string text { get; set; }
            public string value { get; set; }
            public string packagename { get; set; }
            public string UPDATED_BY { get; set; }
            public Nullable<System.DateTime> UPDATED_DATE { get; set; }
            public Nullable<int> prio_id { get; set; }
            public Nullable<int> update_count { get; set; }
            public string REJECTED_BY { get; set; }
            public Nullable<System.DateTime> REJECTED_DATE { get; set; }
            public Nullable<int> REJECTED_REASON { get; set; }

          //  public int Patient_no { get; set; }
          //  public Patients Patients { get; set; }

           // public LabTests labtests { get; set; }
            public virtual LabTests LabTests { get; set; }
            public virtual Patients Patients { get; set; }
        }
    }

This is patient class :

using System;
    using System.Collections.Generic;

    public partial class Patients
    {
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
        public Patients()
        {
            this.LAB_PARA_RESULTS = new HashSet<LAB_PARA_RESULTS>();
            this.LAB_RESULTS = new HashSet<LAB_RESULTS>();
        }

        public int Patient_No { get; set; }
        public string Patient_Name { get; set; }
        public Nullable<int> Age { get; set; }
        public string Mobile { get; set; }
        public string Email { get; set; }
        public string Address { get; set; }
        public Nullable<int> Gender { get; set; }
        public string Patient_id { get; set; }
        public Nullable<int> Natid { get; set; }
        public byte[] insurance_card { get; set; }
        public byte[] ID_card { get; set; }
        public string patient_Name_Arabic { get; set; }
        public Nullable<int> catid { get; set; }
        public Nullable<System.DateTime> DateOfBirth { get; set; }
        public Nullable<System.DateTime> DateAdded { get; set; }
        public string AddedBy { get; set; }
        public string HijriBirthDate { get; set; }
        public string PCfileNo { get; set; }
        public string GregBirthDate { get; set; }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<LAB_PARA_RESULTS> LAB_PARA_RESULTS { get; set; }
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
        public virtual ICollection<LAB_RESULTS> LAB_RESULTS { get; set; }
    }
}

This is the controller :

public ActionResult CashData(int id)
        {
            var tables = new Orders_Tables
            {
                LabResults = db.LAB_RESULTS
                             .Include(p=>p.patient_no)
                             .Include(t=>t.TESTID)
                             .Where(o => o.ORDER_ID == id).ToList(),
                labtests = db.LabTests.ToList(),
                patients = db.Patients.ToList()
            };
            return View(tables);
        }

This is the view :

@model AljawdahNewSite.Models.Orders_Tables
@{
    ViewBag.Title = "CashData";
    Layout = "~/Views/Shared/_LayoutPatients.cshtml";
}

<h2>CashData</h2>

<ul class="nav nav-tabs">
    <li class="nav-item">
        <a class="nav-link active" data-toggle="tab" href="#home">Laboratory Results</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" data-toggle="tab" href="#menu1">Departments</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" data-toggle="tab" href="#menu2">Incentives</a>
    </li>
</ul>
<div class="tab-content">
    <div class="tab-pane container active" id="home">
        <h3 class="text-center text-uppercase">List of Employee</h3>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>@Html.DisplayNameFor(m => m.LabResults.FirstOrDefault().patient_no)</th>
                    <th>@Html.DisplayNameFor(m => m.LabResults.FirstOrDefault().NORMAL_RESULT)</th>
                    <th>@Html.DisplayNameFor(m => m.LabResults.FirstOrDefault().APPROVED_DATE)</th>
                    <th>@Html.DisplayNameFor(m => m.patients.FirstOrDefault().Patient_Name)</th>
                    <th>@Html.DisplayNameFor(m => m.labtests.FirstOrDefault().TestName)</th>

                </tr>
            </thead>
            @foreach (var employee in Model.LabResults)
            {
                <tr>
                    <td>@employee.patient_no</td>
                    <td>@employee.NORMAL_RESULT</td>
                    <td>@employee.APPROVED_DATE</td>
                    <td>@employee.Patients.Patient_Name</td>
                    <td>@employee.LabTests.TestName</td>

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

I checked the solutions but its different case , I checked this link :

A specified Include path is not valid. The EntityType does not declare a navigation property with the name *

How to solve this error the error appeared in the controller ?

解决方案

Like mentioned in comment, you couldn't include properties, just entities, the result will be like :

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

Include documentation

这篇关于指定的包含路径无效.EntityType &amp;#39;DB_A50B96_aljawdahlabModel.LAB_RESULTS&amp;#39;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
C#/.NET最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆