C # Linq-to-SQL Trying to fetch multiple samples
I got this SQL code in SP: (MS SQL 2008)
DECLARE @type tinyint
SELECT @type = Type FROM Contents WHERE ContentID = @ContentID
SELECT [ParentContentID], [Headline], [ShortDescription], [CategoryID], [Type], [State], [DatePublished], [Name] FROM Contents INNER JOIN Users ON Users.ID = Contents.PublishedBy WHERE ContentID = @ContentID
IF (@type = 2) -- Content with text
BEGIN
SELECT [Preamble], [ContentText], [FaceBook], [Twitter], [PrintPage], [TipAFriend] FROM ContentText WHERE ContentID = @ContentID
END
SELECT [ID], [ImagePath], [ImageType] FROM ContentImages WHERE ContentID = @ContentID
SELECT [ID], [BoxID] FROM ContentBoxes WHERE ContentID = @ContentID
I thought I should be smart, so I added the Linq-to-SQL class to my project and dragged the SP into the class. However, I cannot access the data from the second, third and fourth select statements. I was hoping that the Linq-to-SQL class would create 4 data tables with information, allowing me to access them, for example: data [2] .Row [0] .ImagePath.
Do I need to create my own code to get the code from the SQL server to get this functionality?
source to share
LINQ to SQL supports many result sets from stored procedures. You will want to look at the documentation for IMultipleResults
, and you will need to write some code in the context of the data in partial (and not just rely on what the developer creates). Some links to get started:
- IMultipleResults Interface
- Linq to SQL Stored Procedures with Multiple Results
- More
IMultipleResults
questions here on StackOverflow
source to share
I don't think linq-to-sql supports multiple result sets out of the box.
PLINQO, the set of CodeSmith templates I'm using for my current project, does a great job with this: PLINQO: Stored Procedures with Multiple Result Sets
source to share