Dave Bell

Dave Bell

  • 1.5k
  • 108
  • 7.2k

How to fetch non-entity data using DTO from Stored Procedure

May 17 2023 12:39 AM

I have written a stored procedure which returns below data -

    Datex       Score  
2023-04-05  1
2023-04-12  1
2023-04-19  1
2023-04-26  2
2023-05-03  2
2023-05-10  4
2023-05-17  4
2023-05-24  4
2023-05-31  5
2023-06-07  6

I wish to call this using C# EF

I created a DTO object as

public class CummGraphDTO
    {
        
        public DateTime Datex { get; set; }
        public int? Score { get; set; }
        
    }

Now I am trying to call it with

await _context.Database.SqlQuery<CummGraphDTO>($"exec dbo.GetCummulative").ToListAsync();

However, it does not seem to work. What is the correct way to fetch the data? 


Answers (2)