none
Stored procedure with multiple resultset RRS feed

  • Question

  • If  I have a stored procedure that returns multiple result sets and then I drag and drop the stored procedure on .dbml surface to create C# classes why its not creating a corresponding class for second resultset. I get C# class for only the first result set

    Monday, August 27, 2012 10:03 PM

Answers

  • Hi lax4u;

    To your question, " Since designer is not creating C# class for second result set, developer has to manually create.", Yes you do.

    All is the same as stated in the article I posted. What you need to do now is to create one or more classes to hold the result sets that are returned that do not have a class already in the DBML file. The classes must have the same number of properties and names as what will be received from the SP. The order of the ResultType must be in the same order as what is being returned. 

    [Function( Name = "ReturnMultipleRS" )]
    [ResultType( typeof( MyProductClass ) )]
    [ResultType( typeof( MyCustomerClass ) )]

    That is all that should be needed.

    To your question, "Is there any way to automatically create C# classes for second result set.", no there is not.

       


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alexander Sun Monday, September 3, 2012 9:12 AM
    Tuesday, August 28, 2012 8:25 PM

All replies

  • Hi lax4u;

    Please see this article, LINQ to SQL: returning multiple result sets, will show how to get both results.

      


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Tuesday, August 28, 2012 2:26 PM
  • Thanks..that partially solved my problem. 

    The stored procedure in the above example returns "Customer" and "Product" as two different result sets which corresponds to two exact tables/ C# classes. So in this example you don't have to manually create C# classes.

    In my case( and in most of the cases in reality) the result set will consist of columns from multiple tables. Since designer is not creating C# class for second result set, developer has to manually create.

    Is there any way to automatically create C# classes for second result set.

    Tuesday, August 28, 2012 6:33 PM
  • Hi lax4u;

    To your question, " Since designer is not creating C# class for second result set, developer has to manually create.", Yes you do.

    All is the same as stated in the article I posted. What you need to do now is to create one or more classes to hold the result sets that are returned that do not have a class already in the DBML file. The classes must have the same number of properties and names as what will be received from the SP. The order of the ResultType must be in the same order as what is being returned. 

    [Function( Name = "ReturnMultipleRS" )]
    [ResultType( typeof( MyProductClass ) )]
    [ResultType( typeof( MyCustomerClass ) )]

    That is all that should be needed.

    To your question, "Is there any way to automatically create C# classes for second result set.", no there is not.

       


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by Alexander Sun Monday, September 3, 2012 9:12 AM
    Tuesday, August 28, 2012 8:25 PM