I have a stored procedure which returns a multiple set of results (two tables). I call the stored procedure like this:
var result = context.Database.SqlQuery
I think following code could help you.
MultiResultDomain domainEntity = new MultiResultDomain();
var command = _DatabaseContext.Database.Connection.CreateCommand();
command.CommandText = "[dbo].[SPR_GETMultipleResultSP]";
command.CommandType = CommandType.StoredProcedure;
try
{
_DatabaseContext.Database.Connection.Open();
var reader = command.ExecuteReader();
List _listOfCustomer =
((IObjectContextAdapter)_DatabaseContext).ObjectContext.Translate
(reader).ToList();
reader.NextResult();
List _listOfProduct =
((IObjectContextAdapter)_DatabaseContext).ObjectContext.Translate
(reader).ToList();
foreach (var cust in _listOfCustomer)
{
Console.WriteLine("Name: Mr.{0} And Country: {1}", cust.FirstName,
cust.Country);
}
foreach (var product in _listOfProduct)
{
Console.WriteLine("ProductName: {0} And Package: {1}",
product.ProductName, product.Package);
}
domainEntity.Customer = _listOfCustomer;
domainEntity.Product = _listOfProduct;
return domainEntity;
Ref: Click here