LINQ to SQL (Part 6 - Retrieving Data Using Stored Procedures)
page 8 of 11
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 47811/ 85

Handling Multiple Result Shapes from SPROCs

When a stored procedure can return multiple result shapes, the return type of the SPROC method on the DataContext cannot be strongly typed to a single class shape.  For example, consider the SPROC below which returns either a product result or an order result depending on the input parameter:

Figure 18

 

LINQ to SQL supports the ability to create SPROC helper methods that can return either a Product or Order shape by adding a partial "NorthwindDataContext" class to the project that defines a method (which in this case we'll call "VariablesShapeSample") that invokes the SPROC and returns an IMultipleResult object like so:

VB:

Figure 19

C#:

Figure 20

Once this method is added into our project we can then call it and convert the result to be either a Product or Order sequence when we are using it:

VB:

Figure 21

C#:

Figure 22


View Entire Article

User Comments

Title: Programmer   
Name: Alexander
Date: 2012-11-08 4:51:26 PM
Comment:
Your Figure or pictures don't show up
Title: Use Teporary table   
Name: Ashok Kumar
Date: 2011-07-16 3:28:51 AM
Comment:
if we are fetching the combination of table order and product form database then structure of the newly table will not be match with the mapped table order or price details due to column how to handle this






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-20 2:56:34 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search