Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Use Stored Procedures Mapped for Sequential Result Shapes (LINQ to SQL)

This kind of stored procedure can generate more than one result shape, but you know in what order the results are returned. Contrast this scenario with the scenario where you do not know the sequence of the returns. For more information, see How to: Use Stored Procedures Mapped for Multiple Result Shapes (LINQ to SQL).

Here is the T-SQL of a stored procedure that returns multiple result shapes sequentially:

CREATE PROCEDURE MultipleResultTypesSequentially
select * from products
select * from customers
	public IMultipleResults MultipleResultTypesSequentially()
		IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())));
		return ((IMultipleResults)(result.ReturnValue));

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

Northwnd db = new Northwnd(@"c:\northwnd.mdf");

IMultipleResults sprocResults =

// First read products. 
foreach (Product prod in sprocResults.GetResult<Product>())

// Next read customers. 
foreach (Customer cust in sprocResults.GetResult<Customer>())

Community Additions

© 2015 Microsoft