加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

entity-framework – 数据读取器与指定的模型不兼容

发布时间:2020-12-16 04:24:53 所属栏目:asp.Net 来源:网络整理
导读:我通过Add – 在现有模型(edmx)中添加存储过程来运行存储过程.功能导入. 我收到以下错误. 数据读取器与指定的“dbModel.stored_procedure_Result”不兼容.类型为“UID”的成员在数据读取器中没有具有相同名称的相应列. Modle的_Result类如下 public partial
我通过Add – >在现有模型(edmx)中添加存储过程来运行存储过程.功能导入.

我收到以下错误.

数据读取器与指定的“dbModel.stored_procedure_Result”不兼容.类型为“UID”的成员在数据读取器中没有具有相同名称的相应列.

Modle的_Result类如下

public partial class stored_procedure_Result
{
    public int UID { get; set; }
    public int SYSTEM_ID { get; set; }
    public byte ACTIVE { get; set; }
    public string LEVEL { get; set; }
    public string SYSTEM_CODE { get; set; }
    public string SYSTEM_NAME { get; set; }
    public Nullable<int> SYSTEM_SUB_TYPE { get; set; }
    public Nullable<int> PM_ID { get; set; }
}

此类的底线发生错误

using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Core.Objects;
using Company.Product.Domain.Models;

namespace Company.Product.Domain.Data
{
    public partial class BusinessPartnerDataContext : DbContext
    {
        public BusinessPartnerDataContext()
            : base("name=BusinessPartnerDataContext")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }


        public virtual ObjectResult<stored_procedure_Result> stored_procedure(Nullable<int> pCId,Nullable<int> pSystemId,Nullable<bool> pParameterShow,Nullable<bool> pRETActive,Nullable<bool> pAllLevels,Nullable<bool> pSystemSubTypeShow,Nullable<bool> pShowResultSet)
        {
            ((IObjectContextAdapter)this).ObjectContext.MetadataWorkspace.LoadFromAssembly(typeof(stored_procedure_Result).Assembly);

            var pCIdParameter = pCId.HasValue ?
                new ObjectParameter("pCId",pCId) :
                new ObjectParameter("pCId",typeof(int));

            var pSystemIdParameter = pSystemId.HasValue ?
                new ObjectParameter("pSystemId",pSystemId) :
                new ObjectParameter("pSystemId",typeof(int));

            var pParameterShowParameter = pParameterShow.HasValue ?
                new ObjectParameter("pParameterShow",pParameterShow) :
                new ObjectParameter("pParameterShow",typeof(bool));

            var pRETActiveParameter = pRETActive.HasValue ?
                new ObjectParameter("pRETActive",pRETActive) :
                new ObjectParameter("pRETActive",typeof(bool));

            var pAllLevelsParameter = pAllLevels.HasValue ?
                new ObjectParameter("pAllLevels",pAllLevels) :
                new ObjectParameter("pAllLevels",typeof(bool));

            var pSystemSubTypeShowParameter = pSystemSubTypeShow.HasValue ?
                new ObjectParameter("pSystemSubTypeShow",pSystemSubTypeShow) :
                new ObjectParameter("pSystemSubTypeShow",typeof(bool));

            var pShowResultSetParameter = pShowResultSet.HasValue ?
                new ObjectParameter("pShowResultSet",pShowResultSet) :
                new ObjectParameter("pShowResultSet",typeof(bool));

            return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<stored_procedure_Result>("stored_procedure",pCIdParameter,pSystemIdParameter,pParameterShowParameter,pRETActiveParameter,pAllLevelsParameter,pSystemSubTypeShowParameter,pShowResultSetParameter);
        }
    }
}

Sored程序如下

ALTER PROCEDURE STORED_PROCEDURE 
AS 
DECLARE @SYSTEMS TABLE (UID int NOT NULL IDENTITY(1,1),SYSTEM_ID int NOT NULL,ACTIVE tinyint NOT NULL,[LEVEL] char(2) NOT NULL,SYSTEM_CODE char(2) NULL,SYSTEM_NAME varchar(50) NULL,pm_ID int NULL,SYSTEM_SUB_TYPE int NULL)
INSERT INTO @SYSTEMS
VALUES (1,62,1,'LEVEL','CODE','NAME')
SELECT UID,SYSTEM_ID,ACTIVE,LEVEL,SYSTEM_CODE,SYSTEM_NAME
FROM @SYSTEMS RETURN 0

程序结果如下

UID         SYSTEM_ID     ACTIVE     LEVEL      SYSTEM_CODE     SYSTEM_NAME

 1           62           1         LEVEL               CODE           NAME

有些帖子建议从存储过程中删除RET语句,我尝试在存储过程中注释RET语句,但它没有帮助

有些帖子建议检查列名,我在复杂类型中列出了列名,列名完全匹配

有些帖子建议_Result类中的所有列都应该从过程中删除,但_Result类是自动生成的,但是我也尝试删除最后两列,但它没有帮助..
此外,错误显示“UID”列,但是在过程,过程结果,_Result类中出现.

我觉得错误在一些参考文献中

using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Core.Objects;
using Company.Product.Domain.Models;

当“从数据库更新模块”时,它总是抛出错误
“无法将System.Data.Object转换为System.Data.Entity.Core.Objects”

解决方法

请问,如果你按照这些步骤怎么办?

1 – 打开模型端点击模型浏览器

2 – 打开“复杂类型”文件夹并删除stored_procedure_Result

3 – 打开“存储过程”文件夹,然后双击您的过程

4 – 获取列信息

5 – 创建新的复杂类型

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读