【问题标题】:select data using stored procedure使用存储过程选择数据
【发布时间】:2015-05-12 20:17:17
【问题描述】:

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

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.

【问题讨论】:

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


    【解决方案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)
    

    【讨论】:

    • 我这样尝试..但我收到错误{"The function import 'FlairEntities.Sp_GetAttendanceBwDates' cannot be executed because it is not mapped to a store function."}
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-09
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 2017-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多