MultipleResultSets stored procedure entity framework asp.net
ALTER PROCEDURE [dbo].[GetAll] AS BEGIN SET NOCOUNT ON; SELECT * FROM Customers SELECT * FROM Orders SELECT * FROM ProductsEND
The Stored PROCEDURE returns three tables, if you want to use the SqlCommand object , you don't use ExecuteReader(). the best way is that you change your Sql statement and make it return a single table result.
>>1. i would suggest you try use DataSet and fill the DataSet. Then the DataSet would get three tables , default Table0,Table1,Table2 etc.
>>2. If you use Linq to Sql, i would suggest you try the codes:
// 6. Execute the command and materialize the car entitiesusing(IDataReader dataReader = oaCommand.ExecuteReader()){List<Customer> cars = dbContext.Translate<Customer>( dataReader asDbDataReader).ToList();// 7. Advance to the next result sets dataReader.NextResult();List<Order>Orders= dbContext.Translate<Order>( dataReader asDbDataReader).ToList(); ...}
check here:
How to: Execute Stored Procedures Returning Multiple Result Sets
>>3. If you use Entity Framework, i would suggest you try the codes:
// 6. Execute the command and materialize the car entitiesusing(IDataReader dataReader = oaCommand.ExecuteReader()){// ((IObjectContextAdapter)db)// .ObjectContext// .Translate<Blog>(reader, "Blogs", MergeOption.AppendOnly);List<Customer> cars =((IObjectContextAdapter)dbContext).ObjectContext.Translate<Customer>(dataReader asDbDataReader).ToList();// List<Customer> cars = dbContext.Translate<Customer>(dataReader as DbDataReader).ToList();// 7. Advance to the next result sets dataReader.NextResult();List<Order>Orders=((IObjectContextAdapter)dbContext).ObjectContext.Translate<Order>(dataReader asDbDataReader).ToList(); dataReader.NextResult();List<Product>Products=((IObjectContextAdapter)dbContext).ObjectContext.Translate<Product>(dataReader asDbDataReader).ToList();// List<Category> categories = dbContext.Translate<Category>(dataReader as DbDataReader).ToList();}
check here:
How to: Stored Procedures with Multiple Result Sets
http://msdn.microsoft.com/en-us/data/jj691402.aspx
: