存储过程和Linq到实体错误:数据读取器与指定的“CompSecCoreSnapShot1Model.CoreAddresses”不兼容。类型为“AddressID”的成员在数据读取器中没有相应的具有相同名称的列。 [英] Stored Procedure and Linq to Entities Error: The data reader is incompatible with the specified 'CompSecCoreSnapShot1Model.CoreAddresses'. A member of the type, 'AddressID', does not have a corresponding column in the data reader with the same name.

查看:143
本文介绍了存储过程和Linq到实体错误:数据读取器与指定的“CompSecCoreSnapShot1Model.CoreAddresses”不兼容。类型为“AddressID”的成员在数据读取器中没有相应的具有相同名称的列。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被这个错误困住了。

数据读取器与指定的'CompSecCoreSnapShot1Model.CoreAddresses'不兼容。类型为"AddressID"的成员在数据读取器中没有相应的列具有相同的名称。

确定地址ID设置为主键,自动增量但是它要求AddressID?

到目前为止我做了什么:
- 将存储过程 spCreateNewAddress 添加到Linq to Entity模型中 - 进行建模浏览器> entitycontainer>功能导入>右键单击创建了一个函数import>

添加了以下内容:
存储过程名称: spCreateNewAddress
函数导入名称: spCreateNewAddress (将其命名为相同,因为我读过你也需要)
返回类型:实体: CoreAddresses


这是我的存储过程:

 ALTER PROCEDURE spCreateNewAddress 



@Address nvarchar(250),

@City nvarchar( 50),

@ZipCode nvarchar(50),

@StateID int



AS

开头

SET NOCOUNT ON



插入CoreAddresses



地址,

城市,

ZipCode,

StateID





价值



@地址,

@City,

@ZipCode ,

@StateID











结束





这是我执行的代码行:

 var newAddress = testcore.spCreateNewAddress(tbxAgencyAddress.Text,

tbxAgencyCity.Text,

tbxAgencyZipCode.Text,

stateid);

这是它抱怨的行:

 return base.ExecuteFunction< CoreAddresses>(" spCreateNewAddress",addressParameter,cityParameter,zipCodeParameter,stateIDParameter); 

表:核心地址
包含以下

- -AddressID (主键自动增量)
- 地址
- 城市
- 纬编代码
-StateID


谢谢你
Stephen


解决方案

Stephen,

如果没有看到您的EF定义,我不知道这是否正确。但是,查看存储过程,您的模型中可能有一个名为AddressID的列未传递到sproc中,该字段是模型中的一个键。

通常在使用时执行插入的sproc,您希望将新的AddressID拉回到模型中。您可以通过在SPROC末尾加上一行代表"SELECT @@ IDENTITY AS AddressID"的行来完成此操作。 (我不是SqlServer大师,可能有更安全的方法来做到这一点)。

然后,在存储过程映射中,将AddressID映射为输出参数。

如果没有帮助,请回复相关定义模型。<登记/>
克里斯

I have been stumped on this error.

The data reader is incompatible with the specified 'CompSecCoreSnapShot1Model.CoreAddresses'. A member of the type, 'AddressID', does not have a corresponding column in the data reader with the same name.

Ok AddressID is set to a primary key, autoincrementing but it asks for the AddressID?

What I have done thus far:

-Added the stored procedure spCreateNewAddress to the Linq to Entity Model
-Went to model browser > entitycontainer > function imports > right clicked created a function import >

Added the following:
stored procedure name: spCreateNewAddress 
function import name: spCreateNewAddress  (named this the same because I read you need too)
return type: Entities: CoreAddresses


Here is my stored procedure:

ALTER PROCEDURE spCreateNewAddress

	

	@Address nvarchar(250),

	@City nvarchar(50),

	@ZipCode nvarchar(50),

	@StateID int

	

AS

Begin

SET NOCOUNT ON 



Insert Into CoreAddresses

(  	

	Address,

	City,

	ZipCode,

	StateID

)



Values

(

	@Address,

	@City,

	@ZipCode,

	@StateID 

	

)







End



This is the line of Code I execute:

 var newAddress = testcore.spCreateNewAddress(tbxAgencyAddress.Text,

                                                         tbxAgencyCity.Text,

                                                         tbxAgencyZipCode.Text,

                                                         stateid);

This is the line its complaining about:

  return base.ExecuteFunction<CoreAddresses>("spCreateNewAddress", addressParameter, cityParameter, zipCodeParameter, stateIDParameter);

Table: Core Addresses
contains the following

-AddressID (primary key autoincrementing)
-Address
-City
-Zip Code
-StateID


Thank You

Stephen



解决方案

Stephen,

Without seeing your EF definition I don't know if this is right. But, looking at your stored procedure, you probably have a column in your model called AddressID that is not being passed into the sproc, and that field is a key in your model.

Normally when you use a sproc that does an insert, you want to pull the new AddressID back out to your model. You can do this by sticking a line at the end of the SPROC that says something like "SELECT @@IDENTITY AS AddressID". (I'm not a SqlServer guru, and there might be a safer way to do this).

Then, in your stored procedure mapping, you map the AddressID as an output parameter.

If that doesn't help, reply back with the definition model in question.

Chris


这篇关于存储过程和Linq到实体错误:数据读取器与指定的“CompSecCoreSnapShot1Model.CoreAddresses”不兼容。类型为“AddressID”的成员在数据读取器中没有相应的具有相同名称的列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆