Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 2.31 KB

how-to-use-stored-procedures-mapped-for-multiple-result-shapes.md

File metadata and controls

46 lines (33 loc) · 2.31 KB
description title ms.date dev_langs ms.assetid
Learn more about: How to: Use Stored Procedures Mapped for Multiple Result Shapes
How to: Use Stored Procedures Mapped for Multiple Result Shapes
03/30/2017
csharp
vb
c2b84dfe-7fec-489a-92de-45215cec4518

How to: Use Stored Procedures Mapped for Multiple Result Shapes

When a stored procedure can return multiple result shapes, the return type cannot be strongly typed to a single projection shape. Although [!INCLUDEvbtecdlinq] can generate all possible projection types, it cannot know the order in which they will be returned.

Contrast this scenario with stored procedures that produce multiple result shapes sequentially. For more information, see How to: Use Stored Procedures Mapped for Sequential Result Shapes.

The xref:System.Data.Linq.Mapping.ResultTypeAttribute attribute is applied to stored procedures that return multiple result types to specify the set of types the procedure can return.

Example 1

In the following SQL code example, the result shape depends on the input (shape =1 or shape = 2). You do not know which projection will be returned first.

CREATE PROCEDURE VariableResultShapes(@shape int)  
AS  
if(@shape = 1)  
    select CustomerID, ContactTitle, CompanyName from customers  
else if(@shape = 2)  
    select OrderID, ShipName from orders  

[!code-csharpDLinqSprox#4] [!code-vbDLinqSprox#4]

Example 2

You would use code similar to the following to execute this stored procedure.

Note

You must use the xref:System.Data.Linq.IMultipleResults.GetResult%2A pattern to obtain an enumerator of the correct type, based on your knowledge of the stored procedure.

[!code-csharpDLinqSprox#5] [!code-vbDLinqSprox#5]

See also