---
title: "how to read multiple result of procedure in EF 6 as async"  
description: "how to read multiple result of procedure in EF 6 as async"  
author: "Ravi Vishwakarma"  
published: 2025-05-04  
updated: 2025-05-21  
canonical: https://www.mindstick.com/forum/161564/how-to-read-multiple-result-of-procedure-in-ef-6-as-async  
category: "c#"  
tags: ["c#", "java", "python"]  
reading_time: 2 minutes  

---

# how to read multiple result of procedure in EF 6 as async

how to read [multiple](https://www.mindstick.com/blog/12797/iowa-is-expected-to-see-heavy-growth-in-multiple-sectors) [result](https://www.mindstick.com/blog/12011/advantages-of-getting-result-oriented-seo-from-an-agency) of [procedure](https://www.mindstick.com/forum/32/stored-procedure-return-datatype) in EF 6 as [async](https://www.mindstick.com/forum/23036/calling-an-activity-class-from-async-class)

## Replies

### Reply by Utpal Vishwas

In **Entity Framework 6 (EF6)** on **.NET Framework**, reading **multiple result sets from a stored procedure asynchronously** is not directly supported out of the box. EF6 supports `MultipleResults` only via **synchronous** APIs. However, you can do it asynchronously by dropping down to `DbContext.Database.SqlQuery` and `DbDataReader`, using `ExecuteReaderAsync`.

## Goal

Call a stored procedure that returns **multiple result sets**, e.g.:

```plaintext
CREATE PROCEDURE GetData
AS
BEGIN
    SELECT * FROM Products;
    SELECT * FROM Categories;
END
```

## Solution: Use `DbCommand` + `ExecuteReaderAsync`

Here’s a full example using **ADO.NET with EF6 DbContext** to read multiple result sets asynchronously.

### Step-by-Step Example

```cs
public async Task<(List<Product> Products, List<Category> Categories)> GetMultipleResultsAsync()
{
    using (var context = new YourDbContext())
    {
        var conn = context.Database.Connection;

        if (conn.State != ConnectionState.Open)
            await ((DbConnection)conn).OpenAsync();

        using (var command = conn.CreateCommand())
        {
            command.CommandText = "GetProductAndCategory";
            command.CommandType = CommandType.StoredProcedure;

            using (var reader = await ((DbCommand)command).ExecuteReaderAsync())
            {
                var products = ((IObjectContextAdapter)context)
                    .ObjectContext
                    .Translate<Product>(reader)
                    .ToList();

                await reader.NextResultAsync();

                var categories = ((IObjectContextAdapter)context)
                    .ObjectContext
                    .Translate<Category>(reader)
                    .ToList();

                return (products, categories);
            }
        }
    }
}
```

## Calling the Method

In your controller or service:

```cs
public async Task<ActionResult> Index()
{
    var result = await GetMultipleResultsAsync();

    var products = result.Products;
    var categories = result.Categories;

    return View(new MyViewModel
    {
        Products = products,
        Categories = categories
    });
}
```

## Explanation

| Part | Purpose |
| --- | --- |
| `DbContext.Database.Connection` | Gets the underlying ADO.NET connection. |
| `ExecuteReaderAsync()` | Executes the command and returns a `DbDataReader`. |
| `Translate<T>()` | Maps raw data to your EF entity. |
| `NextResultAsync()` | Advances to the next result set. |

## Notes

1. `Translate<T>()` is only available in EF6 through `ObjectContext`.
2. This pattern requires manual mapping, but it’s the **only async-compatible way** in EF6 to handle multiple result sets.


---

Original Source: https://www.mindstick.com/forum/161564/how-to-read-multiple-result-of-procedure-in-ef-6-as-async

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
