locked
Read Data from Sql RRS feed

  • Question

  • User-250884976 posted

    Hi, I have written a stored procedure like this  - 

    Select *,TotalRows = COUNT(*) OVER() from MyTable where ....

    now, I get TotalRows in SSMS, so to access the TotalRows i have updated my Modal class with 

    Class MyClass{

    [NotMapped]

    public int TotalRows{get;set;}

    }

    and i get the TotalRows as 0 from the database please explain me how can i read Totalrows in my API from Database, thank you. 

    Monday, April 6, 2020 9:12 AM

All replies

  • User475983607 posted

    Use a Raw Query.  This concept is covered in the standard docs for the version of EF you are using. 

    https://docs.microsoft.com/en-us/ef/ef6/querying/raw-sql

    https://docs.microsoft.com/en-us/ef/core/querying/raw-sql

    I also recommend the follow blog.

    https://www.learnentityframeworkcore.com/raw-sql

    Monday, April 6, 2020 1:47 PM
  • User-18289217 posted

    slalithp

    Hi, I have written a stored procedure like this  - 

    Select *,TotalRows = COUNT(*) OVER() from MyTable where ....

    now, I get TotalRows in SSMS, so to access the TotalRows i have updated my Modal class with 

    Class MyClass{

    [NotMapped]

    public int TotalRows{get;set;}

    }

    and i get the TotalRows as 0 from the database please explain me how can i read Totalrows in my API from Database, thank you. 

    SELECT *, COUNT(Id) OVER(PARTITION BY ColumnName) AS "TotalRows" FROM MyTable WHERE ...

    HTH

    Tuesday, April 7, 2020 6:18 AM
  • User-250884976 posted

    yeah this thing works, thank you so much.

    Saturday, April 11, 2020 4:26 AM
  • User-719153870 posted

    Hi slalithp,

    If @Kulrom's post helps solve your issue, please mark it as the answer. This can hlep other people who met the similar issue find the solution easily.

    Thanks!

    Best Regard,

    Yang Shen

    Monday, April 13, 2020 1:16 AM