0

How on earch can I access the second, third, fourth result sets?

Controller:

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

View:

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

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

<% } %>

This as simple as it gets... but I can only access the very first resulset. HELP!

1 Answer 1

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) %>
Sign up to request clarification or add additional context in comments.

5 Comments

I'm not sure about Entity Framework, but what I'm trying to accomplish to just calling a sproc and getting the results. I don't want to have to deal with designing the schema, etc. I just want to call a sproc, receive the results and iterate through them and display them on the page.
the "Entity Framework" statement was a joke. You don't have to touch the schema - you have a SPROC, you have added it to L2SQL designer, the article i added shows how to do what you want. What's the issue?
The issue is that within the example you sent me, "typeof" relates to Table Entities that have been dragged into the designer. In my case, that's not what's going on...
@dcolumbus - if you have a stored proc called spSearchDeals on your L2SQL designer, L2SQL will generate a partial class for you called spSearchDealsResult (look for it in the .designer.cs file). All you need to do is c+p that method, and change the return type to IMultipleResult.
I really do appreciate your help, but I have no idea what "all you need to do is c+p that method" means. I've been thrown into this environment and I learn by example... I'm not deep enough into ASP.NET MVC to be able to conceptualize it in my head.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.