I'm trying to call this stored procedure from C #
alter PROCEDURE GetLecturasEnRangoDeFechas
-- Add the parameters for the stored procedure here
@fecha as smalldatetime,
@idParteMaquina int,
@inicio int,
@inicioMasDuracion int,
@dia smalldatetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
declare @inicioFecha as smalldatetime
set @inicioFecha=CONVERT(smalldatetime, DATEADD(s,@inicio,0))
declare @inicioMasDuracionFecha as smalldatetime
set @inicioMasDuracionFecha=CONVERT(smalldatetime, DATEADD(s,@inicioMasDuracion,0))
-- Insert statements for procedure here
select * from Lectura
where
cast(Fecha as Date) =cast(@fecha As Date) and
IdParteMaquina=@idParteMaquina and
(Fecha>=@inicioFecha and
Fecha<=@inicioMasDuracionFecha)
or
(@inicioMasDuracionFecha>@dia and
(@inicioFecha+Fecha<=@inicioMasDuracionFecha))
END
GO
Code C #
using(ProduccionContexto pc=new ProduccionContexto())
{
var lects=pc.Database.SqlQuery<Lectura>("GetLecturasEnRangoDeFechas",fecha,partemaquina.Id, inicio.TotalSeconds, inicioMasDuracion.TotalSeconds, dia);
}
This throws me:
Procedure or function 'GetLecturasEnRangoDeFechas' expects parameter '@fecha', which was not supplied.
And if I do it like this:
using(ProduccionContexto pc=new ProduccionContexto())
{
var lects=pc.Database.SqlQuery<Lectura>("GetLecturasEnRangoDeFechas @fecha,@idParteMaquina,@inicio,@inicioMasDuracion,@dia",fecha,partemaquina.Id, inicio.TotalSeconds, inicioMasDuracion.TotalSeconds, dia);
}
Throws me:
Must declare the scalar variable "@fecha".
What is the correct syntax to call an SP from C # EF 6 CodeFirst