我通过通过Add->函数Import将其添加到现有模型(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);
}
}
}
酸痛的程序如下
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”列,但该列存在于Procedure,过程结果_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-创建新的复合类型
关于entity-framework - 数据读取器与指定型号不兼容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24126767/