使用存储过程选择数据

时间:2015-03-11 06:21:11

标签: sql asp.net sql-server entity-framework entity-framework-4

我使用存储过程来获取该条件满足的多条记录

CREATE PROCEDURE [dbo].[Sp_GetAttendanceBwDates]
@datefrom datetime,
@dateto datetime,
@empid int

ASBEGIN`
select AM.employee_Id,CONVERT(varchar(10),AM.date,111) from
tblAttendanceMaster AM where AM.employee_Id=@empid and
CONVERT(varchar(10),AM.date,111)<=CONVERT(varchar(10),@datefrom,111)
and CONVERT(varchar(10),AM.date,111)=CONVERT(varchar(10),@dateto,111)
END

在后面的代码中,当执行下面的代码时我得到了错误。我没有理解它

var objattendance = context.Sp_GetAttendanceBwDates(datefrom,dateto,emp);

错误消息

occurred in System.Data.Entity.dll but was not handled in user code.
   Additional information: The data reader is incompatible with the specified 'FlairModel.Sp_GetAttendanceBwDates_Result'. A member of the type, 'record_Id', does not have a corresponding column in the data reader with the same name.

1 个答案:

答案 0 :(得分:1)

我猜这个列中存在问题,即当您在框架框架中导入SP时会创建属性,

因此,您的select语句可能存在问题,该语句未返回与生成的复杂类型或生成类型匹配的正确名称

例如此查询具有匹配的列,如

select AM.employee_Id as record_Id''need to be matching property name,
CONVERT(varchar(10),AM.date,111) as date''need to be matching property name
from
tblAttendanceMaster AM where AM.employee_Id=@empid and
CONVERT(varchar(10),AM.date,111)<=CONVERT(varchar(10),@datefrom,111)
and CONVERT(varchar(10),AM.date,111)=CONVERT(varchar(10),@dateto,111)