我通过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”