Good I have this store
@CodRegistro NVARCHAR(20) = NULL,
@UsuarioWindows NVARCHAR(11) = NULL,
@CodPersonal CHAR(5) = NULL,
@IP NVARCHAR(11) = NULL,
@TipoMetodo INT,
@Query NVARCHAR(50) = NULL,
@Pagina INT = NULL,
@Cantidad INT = NULL,
@Total INT = NULL OUT
DECLARE @Desde AS INT --Páginado
DECLARE @Hasta AS INT --Páginado
SET @Desde = ((ABS(@Pagina - 1) * @Cantidad) + 1);
SET @Hasta = @Desde + @Cantidad - 1;
SELECT
@Total = ISNULL(COUNT(*), 0)
FROM
Presupuesto.RelacionCodigoUsuario RCU
WHERE (
RCU.CodPersonal LIKE '%' + @Query + '%' OR
RCU.UsuarioWindows LIKE '%' + @Query + '%'
);
WITH ConsultaCore AS(
SELECT ROW_NUMBER() OVER (ORDER BY RCU.CodRegistro DESC) AS NRegistro,
RCU.CodPersonal,
RCU.CodRegistro,
RCU.UsuarioWindows,
RCU.FechaInsert,
RCU.FechaModif,
RCU.IPInsert,
RCU.IPModif,
RCU.UsuarioInsert,
RCU.UsuarioModif,
RCU.CodPersonal personal,
Presupuesto.GetCC1(RCU.CodPersonal) cc1
FROM
Presupuesto.RelacionCodigoUsuario RCU
WHERE (
RCU.CodPersonal LIKE '%' + @Query + '%' OR
RCU.UsuarioWindows LIKE '%' + @Query + '%'
)
)
SELECT
cc.NRegistro
,cc.CodPersonal
,cc.CodRegistro
,cc.UsuarioWindows
,cc.FechaInsert
,cc.FechaModif
,cc.IPInsert
,cc.IPModif
,cc.UsuarioInsert
,cc.UsuarioModif
,cc.personal
,cc.cc1
FROM ConsultaCore cc
WHERE @Desde <= cc.NRegistro AND @Hasta >= cc.NRegistro
ORDER BY cc.NRegistro ASC;
Well the store is the least important and it works well in the sql when I send the parameters and everything, but from the Entity Framwork it returns the number of records well but all null.
This is my code
public static List<RelacionCodigoUsuario> Buscar(string Query, int Pagina, int Cantidad, ref int Total)
{
List<RelacionCodigoUsuario> data = new List<RelacionCodigoUsuario>();
CostosEntities context = new CostosEntities();
int TipoMetodo = 0;
data = context.Database.SqlQuery<RelacionCodigoUsuario>("Presupuesto.sp_PersonalCentroCosto @CodRegistro, @UsuarioWindows, @CodPersonal, @IP, @TipoMetodo, @Query, @Pagina, @Cantidad, @Total",
new SqlParameter("@CodRegistro", DBNull.Value),
new SqlParameter("@UsuarioWindows", DBNull.Value),
new SqlParameter("@CodPersonal", DBNull.Value),
new SqlParameter("@IP", DBNull.Value),
new SqlParameter("@TipoMetodo", TipoMetodo),
new SqlParameter("@Query", Query),
new SqlParameter("@Pagina", Pagina),
new SqlParameter("@Cantidad", Cantidad),
new SqlParameter("@Total", Total)).ToList();
return data;
}
And this is my class
public class RelacionCodigoUsuario
{
public int NRegistro { get; set; }
public string CodRegistro { get; set; }
public string CodPersonal { get; set; }
public string UsuarioWindows { get; set; }
public string IPInsert { get; set; }
public string IPModif { get; set; }
public string UsuarioInsert { get; set; }
public string UsuarioModif { get; set; }
public DateTime FechaInsert { get; set; }
public DateTime? FechaModif { get; set; }
}