数据读取器与指定的模型不兼容 [英] The data reader is incompatible with the specified model
问题描述
我通过Add - >在现有模型(edmx)中添加存储过程来运行存储过程。功能导入。
我收到以下错误。
数据阅读器与指定的'不兼容' dbModel.stored_procedure_Result。类型为UID的成员在数据读取器中没有相应的列具有相同的名称。
模式的_Result类如下< br $>
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 {获取; set ; }
}
本课程底线发生错误
使用系统;
使用 System.Data.Entity;
使用 System.Data.Entity.Infrastructure;
使用 System.Data.Entity.Core.Objects;
使用 Company.Product.Domain.Models;
namespace Company.Product.Domain.Data
{
public partial class BusinessPartnerDataContext:DbContext
{
public BusinessPartnerDataContext()
: base ( name = BusinessPartnerDataContext)
{
}
protected 覆盖 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级别代码姓名
有些帖子建议t o从存储过程中删除RET语句,我尝试在存储过程中注释RET语句,但它没有帮助
有些帖子建议检查列名,我在复杂类型中列出了列名,列名完全匹配
有些帖子建议_Result中的所有列class应该从过程中被RET,但_Result类是自动生成的,但是我也尝试删除最后两列,但它没有帮助..而且错误显示'UID'列,但是它存在于程序,程序结果,_Result类。
我觉得某些参考文献中有错误
使用系统;
使用 System.Data.Entity;
使用 System.Data.Entity.Infrastructure;
使用 System.Data.Entity.Core.Objects;
使用 Company.Product.Domain.Models;
当从数据库更新模块时,它总是抛出错误,例如无法将System.Data.Object转换为System。 Data.Entity.Core.Objects
请帮助解决方案
检查正在填充的SP和Type模式的返回模式。列匹配不匹配,
I am running a stored procedure by adding it in existing model (edmx) by Add--> function Import.
I received the following error.
The data reader is incompatible with the specified 'dbModel.stored_procedure_Result'. A member of the type, 'UID', does not have a corresponding column in the data reader with the same name.
_Result class of the Modle is as follows
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; }
}
Error occurred on the bottom line of this class
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 procedure is as follows
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
Result of the procedure is
UID SYSTEM_ID ACTIVE LEVEL SYSTEM_CODE SYSTEM_NAME
----- ----------- ------ ----- ------------ -------------------
1 62 1 LEVEL CODE NAME
Some post suggested to remove the RET statement from the stored procedure, I tried with commenting the RET statement in the stored procedure as well , but it didn’t help
Some post suggested to check the column names, I cheked the column names in the complex type , the column names exactly matching
Some post suggested that the all the columns which are there in the _Result class should be RETed from the procedure, but the _Result class is automatically generated, however I tried removing the last two columns as well, but it didn’t help.. Moreover the error says ‘UID’ column, but that is present in the Procedure , procedure result, _Result class .
I am feeling that error is in some references
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.Entity.Core.Objects;
using Company.Product.Domain.Models;
as when the "Update modle from database", it always throws error like "cannot convert System.Data.Object to System.Data.Entity.Core.Objects"
Please help
解决方案 check returned schema of SP and Type schema which is being filled. There is a column mismatch,
这篇关于数据读取器与指定的模型不兼容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!