ASP.NET MVC 2:調用存儲過程,獲取多個結果集 (ASP.NET MVC 2: Calling Stored Procedure, Getting Multiple ResultSets)


問題描述

ASP.NET MVC 2:調用存儲過程,獲取多個結果集 (ASP.NET MVC 2: Calling Stored Procedure, Getting Multiple ResultSets)

如何訪問第二、第三、第四個結果集?

控制器:

var dataContext = new DealDataContext();
XElement xmlString = new XElement("asd");
var deals = dataContext.spSearchDeals(xmlString);
return View(deals);

查看:

<% foreach (spSearchDealsResult d in (IEnumerable)ViewData.Model)
 { %>

    <li> <%: d.TagLabel  %> </li>

<% } %>

這很簡單......但我只能訪問第一個結果集。幫助!


參考解法

方法 1:

Yup, a known limitation/pet hate with Linq To Sql. When you drop stored procs on the canvas, L2SQL generates a method with return type ISingleResult<T>.

The workaround is to use Entity Framework...

Just kidding, here is the L2SQL workaround.

Basically you change the return type to IMultipleResult<T>. (who knew)

On a side note ‑ why are you iterating through items in the ViewData? You are returning the model in the View, you should bind to that model directly.

E.g

Inherits="System.Web.Mvc.ViewPage<IEnumerable<SearchDeal>>"

and then:

<% foreach (var deal in Model.SearchDeals) %>

(by dcolumbusRPM1984)

參考文件

  1. ASP.NET MVC 2: Calling Stored Procedure, Getting Multiple ResultSets (CC BY‑SA 3.0/4.0)

#asp.net-mvc-2 #multiple-resultsets #stored-procedures #linq-to-sql






相關問題

使用 c# 將日期時間轉換為日期 (Convert datetime to date using c#)

如何讓 DotNetNuke 6.2 服務框架對 json 數據進行模型綁定 (How can I get DotNetNuke 6.2 Service Framework to modelbind json data)

下拉級聯 MVC 2 (Drop Down Cascading MVC 2)

如何:(jQuery) 帶有 ASP.NET MVC 2 的模態登錄對話框? (How to: (jQuery) Modal login dialog w/ ASP.NET MVC 2?)

如何在 MVC 應用程序的 URL 中使用日期(MM-dd-yyyy 格式)? (How Do I Use a Date (in the MM-dd-yyyy format) in a URL in an MVC Application?)

如何在 asp mvc 2 中進行上傳工作? (How to make upload work in asp mvc 2?)

如何從 ViewData 為 MVC2 Html.HiddenFor 設置一個值 (How to set a value for MVC2 Html.HiddenFor from ViewData)

複雜模型驗證 (Complex model validation)

ASP.NET MVC 2:調用存儲過程,獲取多個結果集 (ASP.NET MVC 2: Calling Stored Procedure, Getting Multiple ResultSets)

JsonResult 相當於 [DataMember(Name="Test")] (JsonResult equivalent to [DataMember(Name="Test")])

ASP.NET MVC 是否適合活動票務網站? (Is ASP.NET MVC a Good Fit for an Event Ticketing Site?)

跨區通話 (Cross area calls)







留言討論