Hi All,
How get the multiple select query in stored procedure using dot net core using by genric repository.
i using below code to bind details , and using stored Procedure , its was worked stored procedure contain single select query . but when using multple select query in stored procedure its return only one select query result , neet to get all the select Query result ,
ALTER PROC [dbo].[usp_GetClientForProject]
AS BEGIN
SELECT ClientId AS ClientId,[ClientName] AS ClientName , IsActive,IsDeleted
FROM [dbo].[ClientMaster]
-- WHERE IsActive=1
SELECT [BillingCycleID] AS BillingCycleId ,[BillingCycleName] AS BillingCycleName FROM BillingCycle
END
public async Task> GetClientForProject()
{
try
{
Parameters = new GenericParameter
{
ExecuteType = CommandType.StoredProcedure
};
Parameters.SqlCommand = StoredProcedure.GetClientForProject;
var Result = await _repository.ExecuteQueryListAsync
return Result?.ToList();
}
catch (Exception ex)
{
Logger.Log.Error(ex, "GetClientDetailsForProject");
return null;
}
}

Naimish MakwanaPosted Apr 3, 2024, 5:01 AM
In your current implementation, the
ExecuteQueryListAsyncmethod is likely designed to handle a single result set. When you have multipleSELECTstatements in your stored procedure, it returns multiple result sets. To handle this, you need to modify your repository method to accommodate multiple result sets.Here’s an example of how you might adjust your method to handle multiple result sets using Dapper, which is a popular micro-ORM for .NET:
In this example,
QueryMultipleAsyncis used to handle multiple result sets. It returns aGridReaderthat you can use to retrieve your results. TheReadmethod is called for each result set in the order they are returned by the stored procedure.Please note that you’ll need to define the
BillingCycleclass similar to yourClientSelectListItemclass.Remember to adjust this code to fit your actual implementation and error handling strategy. Also, ensure that your repository supports these Dapper methods. If it doesn’t, you might need to extend your repository or consider using Dapper directly for these more complex scenarios.
Thanks