Linq And Multiples Results Returns By A Store Procedure, How LINQPad do this ? |
By Joseph Albahari, Ben Albahari
Price: $49.99 USD
£30.99 GBP
Cover | Table of Contents | Forum
![]() ![]() |
Linq And Multiples Results Returns By A Store Procedure, How LINQPad do this ? |
Jul 18 2008, 06:35 AM
Post
#1
|
|
|
New Member ![]() Group: Members Posts: 4 Joined: 18-July 08 Member No.: 499 |
Hello,
I use a store procedure which returns multiples results from an SQL Server 2005 database. These results are "hand made" by the store procedure, not only a subset of some tables. And in this case SQLMetal don't create a data model for this kind of result (or maybe I missed something ?) But I'm wondering how LinqPad do to retreive all results from this kind of store procedure. If I try to launch the procedure from my code I retreive only the first result... But LinqPad retreive all types returned by the store procedure dynamically (somewhat magical, huh ? All examples I found about multiples results include an attribute [ResultType(typeof(xxx))] in the definition, but in my case the types are not defined. And I don't even know how I can retreive the types returned by the SP. Have you any tips or example code to retreive this kind of results like LinqPad ? Or I've to declare all possibles types returned by the store procedure manually (+/- 30) ? Thanks ! Boris. |
|
|
|
Jul 18 2008, 07:31 AM
Post
#2
|
|
|
Active Member ![]() ![]() Group: Members Posts: 48 Joined: 16-February 08 From: Perth, Australia Member No.: 90 |
Hi Boris
LINQPad actually cheats with stored procedures, and executes them into DataSets rather than using LINQ to SQL. This is precisely to allow dynamically typed results and multiple results sets. The downside of this approach is that you cannot then query the result sets as easily, because you're not getting statically typed entities back. Note that this is different to how LINQPad handles table-valued functions (for which it maps statically typed LINQ to SQL entities, just like in SqlMetal and Visual Studio's designer). The rationale for this decision is that table-value functions always return a fixed schema (and a single result set), so it makes sense to map this to a statically typed entity class. Joe |
|
|
|
Jul 18 2008, 08:46 AM
Post
#3
|
|
|
New Member ![]() Group: Members Posts: 4 Joined: 18-July 08 Member No.: 499 |
Ah ah ! So the only way to handle this kind of "weird" store procedure is to use "classic" dataset...
Thanks for your very quick answer ! Boris |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 28th August 2008 - 01:14 PM |