I am new to ASP.NET Core (3.1). I have a stored procedure that takes two parameters: startDate and endDate.
It returns the following result sets in one go (or execution):

I want to be able to grab the result sets in 3 separate variables because I will like to output them on my view:
For example - for the 1st result set:
foreach (var maindata in Model.MainDataViewModel)
{
maindata.CaseId
maindata.EpisodeId
maindata.SpecimenTag
maindata.PathologyOrderId
}
Likewise for the second and third.
I have attempted to call the stored procedure using this code:
public SpPotentialCandidatesForOncotypeDXViewModel GetPotentialCandidatesForTheOncotypeDXData(DateTime startDate, DateTime endDate)
{
try
{
List pc = new List
{
new SqlParameter("@p0", startDate),
new SqlParameter("@p1", endDate),
};
var da = _dbContext.Database.ExecuteSqlRaw("spPotentialCandidatesForOncotypeDX @p0, @p1", pc.ToArray());
}
catch (Exception ex)
{
AppLog.WriteError("GetPotentialCandidatesForTheOncotypeDXData", ex.Message);
}
// return spPotentialCandidatesForOncotypeDXes;
}
After testing, da has value -1. Via further research I realise ExecuteSqlRaw returns the number of rows affected and not the result sets.
How can I capture these result sets individually and assign to variables?
Prasad RaveendranPosted Aug 19, 2023, 3:56 AM
Using ADO.NET, you can achieve the same as the below. You may need to update this script depends on your use case
Divine FokwaPosted Aug 21, 2023, 10:52 PM
Many thanks @Prasad Raveendran
You saved me many hours. Thank you
Prasad RaveendranPosted Aug 19, 2023, 4:11 AM
if you have patience, requesting you to go through the below links . This may give you some insights on multi result sets.
I would recommend to split this into three stored procedure and invoke it.
https://github.com/nilendrat/EfCoreMultipleResults
https://github.com/dotnet/efcore/issues/6026
https://github.com/KishorNaik/Sol_EF_SqlQuery
https://github.com/dotnet/efcore/issues/8127