Reputation: 5001
Count the results returned from a stored procedure.
I have the following code on my ProductsController
:
[HttpGet]
public ActionResult DailyOffers()
{
var productsList = Products.BuildOffersList();
ViewBag.Title = String.Format("Ofertas de hoje ({0:dd/MM/yyyy})",
DateTime.Now);
ViewBag.CategoryProductsQuantity = ??;
ViewBag.CurrentCategory = "Daily-Offers";
return View(productsList);
}
As you can see, there is a builder on this method. This builder returns the Stored Procedure result. And I want to count the number of results that this procedure returns.
Maybe this?:
ViewBag.CategoryProductsQuantity = productsList.Count;
I'm using C#.NET + MySql + Entity Framework 5 + Razor Engine.
Upvotes: 2
Views: 1438
Reputation: 11
Use parameter "output" on Stored Procedure and create parameter "out" on your method.
@ROWCOUNT INT OUTPUT
SELECT
FROM
WHERE
SET @ROWCOUNT = @@ROWCOUNT
Upvotes: 0
Reputation: 44308
Assuming that Products.BuildOffersList();
does in fact return a List (and not an IEnumerable/IQueryable) then what you've suggested should be fine and won't result in multiple enumerations.
ViewBag.CategoryProductsQuantity = productsList.Count();
Upvotes: 3