C# Linq-to-SQL 尝试接收多个选择
我在 SP 中得到了这个 SQL 代码:(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
我认为我应该很聪明,所以我在我的项目中添加了一个 Linq-to-SQL 类,并将 SP 拖到该类中。但是,我似乎无法访问第二个、第三个和第四个选择语句中的数据。我希望 Linq-to-SQL 类能够生成 4 个包含信息的数据表,从而让我可以像以下方式访问它们:data[2].Row[0].ImagePath。
我是否必须创建自己的代码来从 SQL 服务器获取代码才能获得此功能?
I got this SQL code in a 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 that i should be smart so i added a Linq-to-SQL class to my project and dragged the SP to the class. However, i can't seem to access the data from the second, third and forth select statement. I was hoping that the Linq-to-SQL class would produce 4 data tables with the information thus letting me access them like: data[2].Row[0].ImagePath.
Do i have to create my own code to get the code from the SQL-server in order to get this functionality?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
LINQ to SQL 支持存储过程的多个结果集。您需要查看 IMultipleResults 的文档,并且需要在数据上下文部分中编写一些代码(而不是仅仅依赖于设计器生成的代码)。一些入门链接:
IMultipleResults
问题< /a> 在 StackOverflow 上LINQ to SQL does support multiple results sets from stored procedures. You'll want to look at the documentation for
IMultipleResults
, and you'll need to write some code in the data context partial (rather than just relying on what the designer generates). Some links to start you off:IMultipleResults
questions here on StackOverflow我认为 linq-to-sql 不支持开箱即用的多个结果集。
PLINQO 是我当前项目中使用的一套 CodeSmith 模板,可以很好地处理这个问题:
PLINQO:具有多个结果集的存储过程
I don't think linq-to-sql supports multiple result sets out of the box.
PLINQO, a suite of CodeSmith templates I'm using for my current project, handles this well:
PLINQO: Stored Procedures with multiple result sets