EF存储过程结果集和总计数

时间:2017-10-11 07:33:02

标签: c# sql-server entity-framework stored-procedures

以下存储过程返回已过滤的结果集和总记录。

CREATE PROCEDURE [dbo].[usp_Employee_Search]
(
@LastUpdatedDate DATETIME = NULL,
@PageNo INT = 1,
@PageSize INT = 25,
@SortColumn NVARCHAR(20),
@SortOrder NVARCHAR(4) = 'ASC'
)
AS
BEGIN
DECLARE

@lSortCol NVARCHAR(20),
@lFirstRec INT,
@lLastRec INT,
@TotalCount INT

SET @lSortCol = LTRIM(RTRIM(@SortColumn))

SET @lFirstRec = ( @PageNo - 1 ) * @PageSize
SET @lLastRec = ( @PageNo * @PageSize + 1 )

; WITH ResultsCTE
AS (
SELECT ROW_NUMBER() OVER (ORDER BY
CASE WHEN (@lSortCol = 'EmployeeId' AND @SortOrder='ASC') THEN [EmployeeId] END ASC,
CASE WHEN (@lSortCol = 'EmployeeId' AND @SortOrder='DESC') THEN [EmployeeId] END DESC
) AS ROWNUM,
Count(*) over () AS TotalCount,
[EmployeeId]
FROM [dbo].[Employee]
WHERE
(@LastUpdatedDate IS NULL OR [UpdatedDate] > @LastUpdatedDate)
)

SELECT * INTO #Results FROM ResultsCTE

SELECT @TotalCount = (SELECT count(*) FROM [dbo].[Employee])

SELECT
[EmployeeId]
FROM #Results AS Results
WHERE ROWNUM > @lFirstRec AND ROWNUM < @lLastRec
ORDER BY ROWNUM ASC

RETURN @TotalCount

END



GO

当我将相同内容导入EF时,我发现返回类型只是整数。

 using (TM_Entities db = new TM_Entities())
            {
                db.usp_Employee_Search(
            }

此外,我没有在EDMX的模型浏览器中看到此存储过程的任何复杂类型模型

我想知道如何获取员工数据以及EF

中的总数

0 个答案:

没有答案