---
title: "How to get Generic List from stored procedure by using entity framework ?"  
description: "How to get Generic List from stored procedure by using entity framework ?"  
author: "Anonymous User"  
published: 2019-06-29  
updated: 2019-07-02  
canonical: https://www.mindstick.com/forum/55126/how-to-get-generic-list-from-stored-procedure-by-using-entity-framework  
category: "c#"  
tags: ["c#", "asp.net mvc", "mvc", "mvc2"]  
reading_time: 2 minutes  

---

# How to get Generic List from stored procedure by using entity framework ?

[Please explain](https://www.mindstick.com/forum/344/hi-rohith-i-am-new-for-mvc-please-explain-how-to-set-implicitly-isauthenticated-true) with a suitable example...

## Replies

### Reply by Anonymous User

Try to use it with entity framework.

```
 public void ExecuteList<T>(out List<T> obj, string sql, params object[] parameters) where T : class
        {
            var db = _context;
            var cmd = db.Database.Connection.CreateCommand();
            cmd.CommandText = sql;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddRange(parameters);
            try
            {
                db.Database.Connection.Open();
                using (var reder = cmd.ExecuteReader())
                {
                    obj = ((IObjectContextAdapter)db).ObjectContext.Translate<T>(reder).ToList();

                }
            }
            finally
            {
                db.Database.Connection.Close();
                cmd.Dispose();
            }

        }
```

\


---

Original Source: https://www.mindstick.com/forum/55126/how-to-get-generic-list-from-stored-procedure-by-using-entity-framework

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
