I have an SP which returns an unknown amount of data, here is an example for my query:
MySP:
WHILE (@counter <= @SomeParameter)
BEGIN
Select *
From tblFoo
Where tblFoo.Counter=@counter
@counter=@counter+1
END
In order to store the data efficiently I would like to use DataSet , that will store in each of it’s DataTable the result for each of the Selects.
Since my application is based on EF 5 , I tried to call my SP with my dbContext object, here is what I tried to do.
var ds=db.Database.SqlQuery<DataSet>("MySP @counter @SomeParameter", value1,value2);
That doesn’t seem to work properly.
I thought of using the classic ADO.NET to solve this matter, and use SqlDataAdapter , But I am not sure how to pass the original Connection reference from the dbContext to the SqlDataAdapter.Connection Property since its not the same type.
Note: The reason I am using DataSet and not Entities Collection at this matter is because the results I am getting from the SP could have different columns and therefore I’m not sure if Entities Collection will do.
I would like to know how to call my SP using Entities (or SqlAdapter) to fill each of the tables at my DataSet with the results of each Select from my SP.
I’m fresh at EF so if I am thinking or doing anything wrong any tip would be appriciated.
You can try with this code – based on
SqlDataAdapterclass