我通过Add - >在现有模型(edmx)中添加存储过程来运行存储过程。功能导入。
我收到以下错误。
数据读取器与指定的< dbModel.stored_procedure_Result'不兼容。该类型的成员' UID'在数据阅读器中没有相应的具有相同名称的列。
模块的_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);
}
}
}
索引程序如下
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”