0

I have a stored procedure that returns a DataSet.This stored procedure is exposed in my C# code via an Entity Data Model. How do I get the DataSet in my code? The context keeps trying to automatically generate a strongly-typed set of objects. However, those objects only represent the first result set. My DataSet has 4 result sets in it. Here is the code I'm using:

using (DBDataContext context = new DBDataContext())
{
  var myDataSet = context.LoadData();   // Load data is the name of my sproc

  // how do I get a DataSet here?
}

How do I get a DataSet via LINQ-to-SQL, or LINQ-to-EntityDataModel, or whatever it is called?

Thank you very much for your help

Villager
  • 6,569
  • 22
  • 65
  • 87
  • possible duplicate of [How do I fill a DataSet or a DataTable from a LINQ query resultset ?](http://stackoverflow.com/questions/16/how-do-i-fill-a-dataset-or-a-datatable-from-a-linq-query-resultset) – BrokenGlass May 10 '11 at 16:21
  • Not a duplicate, as this question is about how to handle a stored procedure that returns multiple result sets with different columns in LINQ to SQL. The DataSet bit is a red herring. – Joel Mueller May 10 '11 at 18:10

1 Answers1

1

If you have multiple result sets then you need to write some code - but it's not hard:

There's a few examples out there on the web - e.g.:

They mostly show what's needed as extending your partial datacontext with something like:

    <FunctionAttribute(Name:="dbo.GetMultipleSets")> _
    <ResultType(GetType(Type_1))> _
    <ResultType(GetType(Type_2))> _
    Public Function GetMultipleSets() As IMultipleResults
        Dim result As IExecuteResult = Me.ExecuteMethodCall(Me, CType(MethodInfo.GetCurrentMethod, MethodInfo))
        Dim results As IMultipleResults = DirectCast(result.ReturnValue, IMultipleResults)
        Return results
    End Function

or in C# as something like:

    [Function("dbo.GetMultipleSets"]
    [ResultType(typeof(Type_1))]
    [ResultType(typeof(Type_2))]
    public IMultipleResults GetMultipleSets()
    {
        IExecuteResult result = ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()));
        IMultipleResults results  = (IMultipleResults)result.ReturnValue;
        return results;
    }

Hope that helps

Stuart

Stuart
  • 66,722
  • 7
  • 114
  • 165