EF Core: fetch two SELECT statements in a single call by FromSql()

ef-core-2.2 entity-framework-core sql-server

Question

I have the following SP in which a number of rows and the total number of rows are fetched. How is it possible to call the SP and fetch its content (the 2 SELECT's)?

-- A very simple SP
CREATE PROCEDURE dbo.Sample
AS 
BEGIN

SELECT TOP 10 c.Id, s.CreationDate, s.FirstName, s.LastName
FROM Some_Table s
ORDER BY s.CreationDate

SELECT COUNT(*) 
FROM Some_Table s as TotalRecord    

END

I know it is possible to use Dapper or other ORMs, but I am going to use the EF Core 2.2

1
0
4/15/2020 6:16:50 PM

Popular Answer

Here is what I would do in this case

-- A very simple SP CREATE PROCEDURE dbo.Sample AS BEGIN Declare @TotalCount int SELECT @TotalCount = COUNT(*) FROM Some_Table s as TotalRecord

SELECT TOP 10 @TotalCount as TotalCount, c.Id, s.CreationDate, s.FirstName, s.LastName FROM Some_Table s ORDER BY s.CreationDate

END

0
4/15/2020 6:43:35 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow