問題描述
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) %>