C# Linq-to-SQL 尝试接收多个选择

发布于 2024-08-04 18:36:47 字数 937 浏览 9 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

人事已非 2024-08-11 18:36:47

LINQ to SQL 支持存储过程的多个结果集。您需要查看 IMultipleResults 的文档,并且需要在数据上下文部分中编写一些代码(而不是仅仅依赖于设计器生成的代码)。一些入门链接:

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:

南巷近海 2024-08-11 18:36:47

我认为 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文